KnowledgeBoat Logo

Java Pattern Programs

Write a program in Java to display the following pattern:

11 13 15 
17 19 
21

Java

Java Nested for Loops

5 Likes

Answer

public class KboatPattern
{
    public static void main(String args[]) {
        int term = 11;
        for (int i = 3; i >= 1; i--) {
            for (int j = 1; j <= i; j++) {
                System.out.print(term + " ");
                term += 2;
            }
            System.out.println();
        }
    }
}

Output

BlueJ output of Write a program in Java to display the following pattern: 11 13 15 17 19 21

Answered By

2 Likes