Originally posted by Karthik Rajashekaran:
public class Calc {
public static void main (String args []) {
int total = 0;
for (int i = 0, j = 10; total > 30; ++i, --j) {
System.out.println(" i = " + i + " : j = " + j);
total += (i + j);
}
System.out.println("Total " + total);
}
}
Please tell me why it prints 0
The for loop never be executed so the out put is
Total 0
In for loop you gave condition that total > 30, as total is initialized to 0,
total >30 is false. So it never enters into for loop.