KnowledgeBoat Logo

Java Pattern Programs

Write a program in Java to display the following pattern:

1
2 6
3 7 10
4 8 11 13
5 9 12 14 15

Java

Java Nested for Loops

ICSE

11 Likes

Answer

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

Output

BlueJ output of Write a program in Java to display the following pattern: 1 2 6 3 7 10 4 8 11 13 5 9 12 14 15

Answered By

4 Likes