CodeHub Menu
Home Exercise Practice About Download Portfolio Play Games NEW Privacy Policy Terms Contact
Login / Register

generate the two diffrent patterns using iteration in JAVA

JAVA November 21, 2025 14 views 2 likes
Write two separate programs to generate the following patterns using iteration (loop) statements:

(a)

*
* #
* # *
* # * #
* # * # *

(b)

5 4 3 2 1
5 4 3 2
5 4 3
5 4
5


Answer



Pattern - Java Code

Pattern - Java Code


public class Pattern
{
    public static void main(String args[]) {
        for (int i = 1; i <= 5; i++) {
            for (int j = 1; j <= i; j++) {
                if (j % 2 == 0)
                    System.out.print("# ");
                else
                    System.out.print("* ");
            }
            System.out.println();
        }
    }
}

OUTPUT:



Star Hash Pattern

Pattern Output


14 views 2 likes
Total visits: 2,089 • Unique visitors: 1,285