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
Question
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
Solution
The output of the given Java code will be "6".
Here's the step by step explanation:
- The variable
iis declared and initialized to 1. - The
forloop will run as long asiis less than 6. - Inside the loop, there is a condition
if(i > 3) continue;. Thecontinuestatement skips the current iteration of the loop and continues with the next iteration. In this case, wheniis greater than 3, the loop will skip the current iteration and continue with the next one. - However, there is no code after the
ifstatement inside the loop, so thecontinuestatement doesn't actually change the behavior of the loop. - The loop will increment
iby 1 in each iteration untiliis no longer less than 6. - After the loop finishes, the value of
i(which is now 6) is printed to the console.
Similar Questions
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 will be the output?public class Test{ public static void main(String args[]){ int i = 1; do{ i--; }while(i > 2); System.out.println(i); }}12-10
Determine output:public class Test{ public static void main(String[] args){ int[] x = {1, 2, 3, 4}; int[] y = x; x = new int[2]; for(int i = 0; i < x.length; i++) System.out.print(y[i] + " "); }}
What is the output of the following code :class MyClass {public static void main(String[] args) {int i=1,j=1;for (;i<3;i++){for(;j<4;j++);j++;System.out.print(i + j+" ");}}
e correct answerWhat is the output of the following Java program?class Main { public static void main(String args[]) { final int i; i = 20; i = 30; System.out.println(i); }}
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.