Single Choice
Easy
QWhen one loop is used within another loop, it is said to be a _______________.
ID: #22413
Nested Loops in Java Language
156 views
Question Info
#22413Q ID
EasyDifficulty
Nested Loops in Java Language Topic
Your Answer
Choose the Best Option
Click any option to instantly check if you're correct.
Correct Answer
Explanation
nested loop
Certainly! Here is an example of a nested loop in Java:
public class NestedLoopExample { public static void main(String[] args) { // Outer loop for (int i = 1; i <= 3; i++) { System.out.println("Outer loop iteration: " + i); // Inner loop for (int j = 1; j <= 2; j++) { System.out.println(" Inner loop iteration: " + j); } } } }
Output:
Outer loop iteration: 1 Inner loop iteration: 1 Inner loop iteration: 2 Outer loop iteration: 2 Inner loop iteration: 1 Inner loop iteration: 2 Outer loop iteration: 3 Inner loop iteration: 1 Inner loop iteration: 2
In this example, the outer loop runs 3 times, and for each iteration of the outer loop, the inner loop runs 2 times. This demonstrates how nested loops work in Java.
Continue Practice
Share
Share This Question
Challenge a friend or share with your study group.
More from This Topic