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
Java Programming Language (Article) (Program)
15
Given Input:
Expected Output:
Program:
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();
}
}
}
Output:
This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.
Program:
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(); } } }
Output:
This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.