Reputation: 37
The second for loop is only executing for the first number(999) in the first for loop. I am trying to have the second for loop execute for each number 999-101 in the second.
int num1 = 999;
int num2 = 999;
int test1 = 0;
String test = "";
for(; num1!=110; num1--){
System.out.println("--------"+num1);
for(; num2!=100; num2--){
System.out.println("++++++++"+num2);
test1 = num1*num2;
test = String.valueOf(test1);
//System.out.println("checkpoint 2"+"--------------"+test1);
if(test.length()==5){
if(test.charAt(0)==test.charAt(5) && test.charAt(1)==test.charAt(4) && test.charAt(2)==test.charAt(3)){
System.out.println("checkpoint 1"+"----------"+test);
break;
}
else{
//System.out.println("Fail 1");
}
}
}
}
Upvotes: 0
Views: 49
Reputation: 3534
After the first run of the second loop num2
has the value 100 so the statement num2!=100
is false
and it does not execute. Set the value for num2 to get it to execute for each loop:
for(num2=999; num2!=100; num2--) {
...
}
Upvotes: 3