Computer Applications

Write a program in Java to display the following pattern:

1
3 1
5 3 1
7 5 3 1
9 7 5 3 1

Java

Java Nested for Loops

122 Likes

Answer

public class KboatPattern
{
    public void displayPattern() {
        for (int i = 1; i < 10; i = i + 2) {
            for (int j = i; j > 0; j = j - 2) {
                System.out.print(j + " ");
            }
            System.out.println();
        }
    }
}

Variable Description Table

Program Explanation

Output

Answered By

53 Likes


Related Questions