KnowledgeBoat Logo

Java Pattern Programs

Write a program in Java to display the following pattern:

12345
23456
34567
45678
56789

Java

Java Nested for Loops

ICSE

7 Likes

Answer

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

Output

BlueJ output of Write a program in Java to display the following pattern: 12345 23456 34567 45678 56789

Answered By

3 Likes