LearnFrenzy
Sign in Take a free test

Control Flow Statements · Predict the Output · Question 16

A number pattern from nested loops Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 16 Back to Exercise

What is the output of the following Java program?

Main.java
public class Main {
    public static void main(String[] args) {
        for (int i = 1; i <= 4; i++) {
            for (int j = i; j >= 1; j--) System.out.print(j);
            System.out.println();
        }
    }
}
  • A 1 21 321 4321 Correct
  • B 1 12 123 1234
  • C 4321 321 21 1
  • D 1 22 333 4444
Correct Answer: Option A

Each row counts down from the row number to 1.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links