Home / Programs / Write two separate programs to generate the following patterns using iteration (loop) statements: (a) **  #*  #  **  #  *  #*  #  *  #  * (b) 5 4 3 2 15 4 3 25 4 35 45
🚀 Programming Example

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

👁 111 Views
💻 Practical Program
📘 Step Learning
Learn this program step-by-step with algorithm, source code, output and detailed explanation.

📌 Information & Algorithm

Given Input:


Expected Output:


💻 Program Code

public class RAnsariPattern
{
    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();
        }
    }
}





public class RAnsariPattern
{
    public static void main(String args[]) {
        for (int i = 1; i <=5; i++) {
            for (int j = 5; j >= i; j--) {
                System.out.print(j + " ");
            }
            System.out.println();
        }
    }
}
                        
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.