I have a bunch of numbers.Each digit of those numbers is concatenated n times and then summed. I have to write function which is returns 1 if sum equals number else returns 0.
public static int checkConcatenatedSum(int n, int catlen) {
char[] charArray = String.valueOf(n).toCharArray();
int[] test = new int[charArray.length];
String[] digit = new String[charArray.length];
int sum = 0;
for (int j = 0; j < charArray.length; j++){
for(int i = 0; i < catlen; i++){
digit[j] += charArray[j];
}
test[j] = Integer.parseInt(digit[j]);
sum += test[j];
}
if(sum == n){
return 1;
}
else return 1;
}
digit[j]
begins with null every time.