KnowledgeBoat Logo

Computer Applications

Write a program in Java to display the following patterns.

* * * * 5
* * * 4
* * 3
* 2
1

Java

Java Nested for Loops

3 Likes

Answer

public class KboatPattern
{
    public static void main(String args[])  {
        char ch = '*';
        for (int i = 5; i >= 1; i--) {
            for (int j = i-1; j >= 1 ; j--) 
                    System.out.print(ch + " ");
            System.out.print(i);
            System.out.println();
        }
    }
}

Output

BlueJ output of Write a program in Java to display the following patterns. * * * * 5 * * * 4 * * 3 * 2 1

Answered By

1 Like


Related Questions