Single Choice Easy

QState the type of loop in the given program segment:

for (int i = 5; i ! = 0; i - = 2)
System.out.println(i);

ID: #19882 Inheritance in Java (IS-A) 97 views
Question Info
#19882Q ID
EasyDifficulty
Inheritance in Java (IS-A)Topic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A finite
  • B infinite
  • C null
  • D fixed
Correct Answer

Explanation

The given program segment is a finite loop. The loop will iterate as long as the condition i != 0 is true. The loop variable i starts at 5, and it decreases by 2 in each iteration (i -= 2). The loop will continue until i becomes 0 or less, at which point the condition becomes false, and the loop exits.

So, the correct answer is:

(a) finite

Share This Question

Challenge a friend or share with your study group.