I have a problem with my code. I read a couple of numbers of a text-file. For example: Textfile.txt
1, 21, 333
With my following code I wan
A couple of problems:
factor should be multiplied by 10 in every loopanswer and factor should be re-initialized between the numbers you're parsing:String line = "1,21,333";
for (String retval : line.split(",")) {
int answer = 0;
int factor = 1;
for (int j = retval.length() - 1; j >= 0; j--) {
answer = answer + (retval.charAt(j) - '0') * factor;
factor *= 10;
}
System.out.println(answer);
answer = (answer - answer);
}
OUTPUT
1
21
333