I’ve been toying around with Java recently and I’ve encountered a problem:
Whenever I put System.out.println() or System.out.print() inside a for loop, there is no output on the console.
For example:
package experimental;
public class Main {
public static void main(String args[]) {
recur();
}
public static void recur() {
for(int x = 0; x == 10; x++) {
for(int y = 0; y == 10; y++) {
System.out.print(x + "-" + y + " ");
}
}
}
}
Outputs:
*crickets*
The loop condition isn’t
trueto even begin with…x == 10is nottruewhenx = 0.Had it been, you would’ve also noticed the second loop condition is also not
trueto begin with; similarly ,y == 10is not true asy = 0. You probably confused the condition with one for stopping.Change to the following if you want
x,yto vary from [0, 10):… or the following for [0, 10]: