Knowee
Questions
Features
Study Tools

What will be the output of the following program?public class Test{ public static void main(String args[]){ int i = 0, j = 5 ; for( ; (i < 3) && (j++ < 10) ; i++ ){ System.out.print(" " + i + " " + j ); } System.out.print(" " + i + " " + j ); }}0 6 1 7 2 8 3 80 6 1 7 2 8 3 90 6 1 5 2 5 3 5Compilation Error

Question

What will be the output of the following program?public class Test{ public static void main(String args[]){ int i = 0, j = 5 ; for( ; (i < 3) && (j++ < 10) ; i++ ){ System.out.print(" " + i + " " + j ); } System.out.print(" " + i + " " + j ); }}0 6 1 7 2 8 3 80 6 1 7 2 8 3 90 6 1 5 2 5 3 5Compilation Error

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the program will be " 0 6 1 7 2 8 3 9".

Here's the step by step explanation:

  1. The initial values of i and j are 0 and 5 respectively.
  2. The for loop condition checks if i is less than 3 and if j (incremented by 1) is less than 10.
  3. In the first iteration, i is 0 which is less than 3 and j becomes 6 which is less than 10. So, " 0 6" is printed.
  4. In the second iteration, i becomes 1 which is less than 3 and j becomes 7 which is less than 10. So, " 1 7" is printed.
  5. In the third iteration, i becomes 2 which is less than 3 and j becomes 8 which is less than 10. So, " 2 8" is printed.
  6. In the fourth iteration, i becomes 3 which is not less than 3 and hence the loop breaks.
  7. After the loop, " 3 9" is printed as the final values of i and j are 3 and 9 respectively.

This problem has been solved

Similar Questions

What will be the output of the following program?public class Test{ public static void main(String args[]){ int i = 0, j = 5 ; for( ; (i < 3) && (j++ < 10) ; i++ ){ System.out.print(" " + i + " " + j ); } System.out.print(" " + i + " " + j ); }}0 6 1 7 2 8 3 80 6 1 7 2 8 3 90 6 1 5 2 5 3 5Compilation Erro

Determine output:public class Test{ public static void main(String args[]){ int i; for(i = 1; i < 6; i++){ if(i > 3) continue ; } System.out.println(i); }}23466

What will be the output of the below program?public class Demo { public static void main(String[] args) { int sum = 0; for (int i = 0, j = 0; i < 5 & j < 5; ++i, j = i + 1) { sum += i; } System.out.println(sum); }}

Determine output:public class Test{ public static void main(String args[]){ int i, j; for(i=1, j=0;i<10;i++) j += i; System.out.println(i); }}1011920

What is output of the following code:public class Test{ public static void main(String[] args){ int[] x = {120, 200, 016 }; for(int i = 0; i < x.length; i++) System.out.print(x[i] + " "); }

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.