Select the correct answerWhat is the output of the following program?public class Test{ public static void main(String []args){ int i = 0; for(i = 0; i < 10; i++){ continue; } System.out.println(i); }}OptionsCompilation error0109
Question
Select the correct answerWhat is the output of the following program?public class Test{ public static void main(String []args){ int i = 0; for(i = 0; i < 10; i++){ continue; } System.out.println(i); }}OptionsCompilation error0109
Solution
The correct answer is 10.
Here's the step by step explanation:
- The variable
iis initialized to 0. - The
forloop starts withi = 0and continues untili < 10. - The
continuestatement is encountered which causes the loop to skip the rest of the current iteration and immediately start the next iteration. - This process repeats until
iis no longer less than 10 (i.e.,ibecomes 10). - At this point, the loop terminates and the value of
i(which is now 10) is printed.
Similar Questions
Select the correct answerWhat will be the output of the following Java program?class main_class { public static void main(String args[]) { int code = 10; if (code == 10) { int code = 6; System.out.println(code); } } }OptionsCompilation error610Runtime error
elect the correct answerWhat is the output of the following code snippet?int i = 0;for(i = 0 ; i < 5; i++){}System.out.println(i);Options405Compilation Error
Select the correct answerWhat is the output of the following code snippet?for (int i = 0; i < 5; i++) { System.out.print(i + " ");}Options0 1 2 3 40 1 2 3Compilation error1 2 3 4 5
Select the correct answerWhat will be the output of the following Java program? class CT { public static void main(String args[]) { try { int x, y; y = 0; x = 5 / y; System.out.print("A"); } catch(ArithmeticException e) { System.out.print("B"); } } }OptionsBACompilation ErrorRuntime Error
Select the correct answerPredict the output of following Java program.?class CT { public static void main(String args[]) { int a; System.out.println(a); } } Optionscompiler errorgarbage value0runtime error
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.