Computer Applications
What will be the output of the following code?
public static void main(String args[])
{
int sum = 0;
for (int i= 1; i <= 5; i++)
{
sum = i;
}
System.out.println(sum);
}
- 15
- 21
- 5
- 0
Related Questions
Which of the following is not a jump statement in Java?
- return
- jump
- break
- continue
How many times will the following code print "Hello"?
for (int i = 1; i <= 5; i++); { System.out.println("Hello"); }- 0
- 1
- 5
- 4
How many times will the following loop execute?
public static void main(String args[]) { int sum = 0; for (int i = 10; i > 5; i++) { sum += i; } System.out.println(sum); }- 5
- 0
- 15
- Infinite loop
How many times will the following loop execute?
public static void main(String args[]) { int i = 1; while (i < 10) if (i++ % 2 == 0) System.out.println(i); }- 4
- 5
- 0
- 10