Computer Applications
How many times will the following code print "Java"?
for (int i = 1; i <= 5; i ++);
{
System.out.println("Java");
}
- 0
- 1
- 5
- 4
Java Iterative Stmts
3 Likes
Answer
1
Reason — Since for loop has a semicolon at its end, the block following the loop will be executed after the for loop is terminated. Thus, Java will be printed only once.
Answered By
2 Likes
Related Questions
Which of the following is an empty loop?
- for(i = 0; i < 5; i++);
- while (i < 5) i++;
- do {i++;} while (i < 5);
- All of these
Which of the following is not a jump statement in Java?
- return
- jump
- break
- continue
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 sum = 0; for (int i = 10; i > 5; i++) { sum += i; } System.out.println(sum); }
- 5
- 0
- 15
- Infinite loop