I have task: to make a java-programm which will print numbers from 000001 to 999999(it's a tram's tickets numbers) and count all numbers which have equilly left and right sides(for example: 024033, 125008, 531900 etc.). I wrote the code:
public class Cycle13 {
public static void main(String[] args) {
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int e = 0;
int f = 1;
int current_b = 0;
int current_c = 0;
int current_d = 0;
int current_e = 0;
int current_f = 0;
int counter = 0;
for (int i = 1; i <= 1000000; ++i) {
if (f >= 10) {
current_f = 10;
f = 0;
}
if (current_f >= 10) {
++e;
current_f = 0;
}
if (e >= 10) {
current_e = 10;
e = 0;
}
if (current_e >= 10) {
++d;
current_e = 0;
}
if (d >= 10) {
current_d = 10;
d = 0;
}
if (current_d >= 10) {
++c;
current_d = 0;
}
if (c >= 10) {
current_c = 10;
c = 0;
}
if (current_c >= 10) {
++b;
current_c = 0;
}
if (b >= 10) {
current_b = 10;
b = 0;
}
if (current_b >= 10) {
++a;
current_b = 0;
}
if (a >= 10) {
break;
}
System.out.print(a);
System.out.print(b);
System.out.print(c);
System.out.print(d);
System.out.print(e);
System.out.print(f);
++f;
if (a + b + c == d + e + f) {
counter++;
}
System.out.println();
}
System.out.print(counter);
}
}
And this code has a strange behavior despite it maked right. I'm sure of it because if set up the condition i<=10000 (i.e four zeros) in the cycle for the code works correctly. If replace the cycle for on the cycle while it would be the same result. Who knows what the problem is?