KnowledgeBoat Logo

Computer Applications

Write a program to display the given pattern:

3
5 6
8 9 10
12 13 14 15

Java

Java Nested for Loops

45 Likes

Answer

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

Variable Description Table

Program Explanation

output

BlueJ output of Pattern Program in Java

Answered By

19 Likes


Related Questions