What will the following code print:

public class ForLoop {
    public static void main(String[] args) {
        for (int i = 0, j = 1; i < 1, j < 2; i++) {
            System.out.print("i=" + i + "; ");
            System.out.print("j=" + j + "; ");
            j++;
        }
    }
}
Explanation
Compilation error is caused by incorrect syntax (using ',') in loop condition
To compile this code ',' must be replaced with && or ||.
',' can be used in the first and third parts of loop declaration. For example:

for (int i = 0, j = 1; i < 1; i++, j++) { ... }

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes