0

I'm new here and I have an assignment about java that i'm not understand on how to do it.Here is the question:
Write a test program that read an integer n and call a method to display a pattern as follows:
1
2 1
3 2 1
4 3 2 1
...
n n-1 ... 3 2 1
The method header is
public static void displayPattern(int n)

5
Contributors
4
Replies
9
Views
5 Years
Discussion Span
Last Post by jalpesh_007
1

Look at what is to be printed on each line. The first line has one number, the second line has two number. Each line starts with its line number and decrements. Make some loops that follows those rules.

0

try with this code it gives the above pattern (in java)

public void displayPattern(int n){
        for (int i = 1; i <= n; i++)
        {
            for (int j = i; j > 0; j--) {
                System.out.print("\t"+j);
            }
            System.out.println("");
        }
}

all the best,
radha krishna .peram

Edited by ~s.o.s~: Added back the code; pardon the mixup. Giving away free code isn't against the forum rules.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.