Computer Applications
Write a program in Java to display the following patterns.
#
* *
# # #
* * * *
# # # # #
Java
Java Nested for Loops
3 Likes
Answer
public class KboatPattern
{
public static void main(String args[]) {
char ch1 = '#', ch2 = '*';
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
if (i % 2 == 0)
System.out.print(ch2 + " ");
else
System.out.print(ch1 + " ");
}
System.out.println();
}
}
}
Output
Answered By
1 Like
Related Questions
Write a program in Java to display the following pattern:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15Write a program in Java to display the following patterns.
1 * * * * * 2 * * * * * 3 * * * * * 4 * * * * * 5
Write a program in Java to display the following patterns.
* * * * 5 * * * 4 * * 3 * 2 1
Write a program in Java to display the following pattern:
1**** 22*** 333** 4444* 55555