From 72fda4214cc8afcfc3258d28667cbb34cc0e79fd Mon Sep 17 00:00:00 2001 From: Paranoid User Date: Mon, 28 Nov 2022 12:55:31 -0500 Subject: [PATCH] refactor(S1121): extract the assignment out of this expression https://sonarcloud.io/project/issues?branch=develop&issues=AYS-_nuPpBLl9srYyCRH&open=AYS-_nuPpBLl9srYyCRH&id=codewars-handbook --- kata/4-kyu/sum-strings-as-numbers/main/Kata.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kata/4-kyu/sum-strings-as-numbers/main/Kata.java b/kata/4-kyu/sum-strings-as-numbers/main/Kata.java index b30239679..b4aa57a12 100644 --- a/kata/4-kyu/sum-strings-as-numbers/main/Kata.java +++ b/kata/4-kyu/sum-strings-as-numbers/main/Kata.java @@ -4,8 +4,10 @@ static String sumStrings(String a, String b) { a = "0".repeat(length - a.length()) + a; b = "0".repeat(length - b.length()) + b; var result = new StringBuilder(length); - for (int r = 0, i = length - 1; i >= 0; i--) { - result.insert(0, (r = a.charAt(i) + b.charAt(i) - 96 + (r / 10)) % 10); + int r = 0; + for (int i = length - 1; i >= 0; i--) { + r = r / 10 + a.charAt(i) + b.charAt(i) - 96; + result.insert(0, r % 10); } return result.toString().replaceFirst("0*", ""); }