Computer Applications
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
Related Questions
How many times will the following code print "Hello"?
for (int i = 1; i <= 5; i++); { System.out.println("Hello"); }- 0
- 1
- 5
- 4
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
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
State whether the following statement is True or False :
To execute a do-while loop, the condition must be true in the beginning.