KnowledgeBoat Logo

Java Pattern Programs

Write a program in Java to display the following pattern:

3
5 6
8 9 10
12 13 14 15

Java

Java Nested for Loops

ICSE

9 Likes

Answer

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

Output

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

Answered By

3 Likes