KnowledgeBoat Logo

Java Pattern Programs

Write a program in Java to display the following pattern:

12345
2345
345
45
5
45
345
2345
12345

Java

Java Nested for Loops

ICSE

2 Likes

Answer

public class KboatPattern
{
    public static void main(String args[]) {
        
        for (int i = 1; i <= 5; i++)
        {
            for (int j = i; j <= 5; j++) {
                System.out.print(j);
            }
            System.out.println();
        }
        
        for (int k = 1; k <= 4; k++) {
            for (int l = 5 - k; l <= 5; l++) {
                System.out.print(l);
            }
            System.out.println();
        }
        
    }
}

Output

BlueJ output of Write a program in Java to display the following pattern: 12345 2345 345 45 5 45 345 2345 12345

Answered By

1 Like