Targer - need to count how many numbers with 6 digit have same summ of left and right 3 digit
What done - prepared 3 methods:
1-st - counting summ of left 3 digit from number - works ok
private static int counterLeft3(int i) {
int digitCounter=0;
int summLeft3=0;
while (digitCounter!=3){
summLeft3=summLeft3+(i%10);
i=i/10;
digitCounter++;
}
return summLeft3;
}
2-nd - counting summ of right 3 digit from number - works ok
private static int counterRight3(int i) {
int summRight3=0;
int buffer;
int counter=0;
while (counter!=3){
summRight3=summRight3+(i%10);
i=i/10;
counter++;
}
buffer =i;
summRight3=0;
while (buffer!=0){
summRight3=summRight3+(buffer%10);
buffer=buffer/10;
}
return summRight3;
}
3-dr - cycle for counting q-ty of numbers - allways return 0. thnink - my mistake thomthing here :
private static void summCounter() {
int counter=0;
for (int i=111110; i<1000000; i++){
if (counterRight3(i)==counterLeft3(i)){
}
counter = counter++;
}
System.out.println("Q-ty is " + counter);
}
debug - example
result for 1-st method
result for 2-nd method
Question - what wrong with 3-rd method, why it allways return just 0 and counter never increase?