Java Pattern Programs

Write a program in Java to display the following pattern:

1   
3  5   
5  7  9   
7  9  11  13   
9  11 13  15  17

Java

Java Nested for Loops

15 Likes

Answer

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

Output

Answered By

3 Likes