Select the correct answerWhat will be the output of the following Java program?class control_statements { public static void main(String args[]) { int sum = 0; for (int u = 5, v = 5; u < 10 & v < 10; ++u, v = u + 1) sum += u; System.out.println(sum); } }Options1015compilation error26
Question
Select the correct answerWhat will be the output of the following Java program?class control_statements { public static void main(String args[]) { int sum = 0; for (int u = 5, v = 5; u < 10 & v < 10; ++u, v = u + 1) sum += u; System.out.println(sum); } }Options1015compilation error26
Solution
The correct answer is 15.
Here's the step-by-step explanation:
-
The program starts with the declaration of the
sumvariable, which is initially set to 0. -
Then, a
forloop is initiated with two variablesuandv, both set to 5. -
The condition for the loop to continue is
u < 10 & v < 10. This means the loop will continue as long as bothuandvare less
Similar Questions
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); }}
Select the correct answerWhat will be the output of the following Java program? class CT { public static void main(String args[]) { try { int a, sum; sum = 10; for (a = -1; a < 3; ++a) sum = (sum / a); } catch(ArithmeticException e) { System.out.print("0"); } System.out.print(sum); } }Options0Compilation ErrorRuntime Error05
What will be the output of the program? int i = 1, j = 10; do { if(i > j) { break; } j--; } while (++i < 5); System.out.println("i = " + i + " and j = " + j); i = 6 and j = 5 i = 5 and j = 5 i = 6 and j = 6 i = 5 and j = 6
Select the correct answerWhat will be the output of the following Java program?class java { public static void main(String args[]) { int var1 = 3; int var2 = 8; if ((var2 = 2) == var1) System.out.print(var2); else System.out.print(++var2); } }Options4213
Select the correct answerWhat will be the output of the following Java code?class array_output { public static void main(String args[]) { int array_variable[][] = {{ 1, 2, 3}, { 4 , 5, 6}, { 7, 8, 9}}; int sum = 0; for (int i = 1; i < 3; ++i) for (int j = 1; j < 3 ; ++j) sum = sum + array_variable[i][j]; System.out.print(sum / 6); } }Options8413
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.