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

10 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

Answered By

4 Likes