Java Pattern Programs

Write a program in Java to display the following pattern:

12345
23456
34567
45678
56789

Java

Java Nested for Loops

10 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

Answered By

3 Likes