Computer Applications
Write a program in Java to display the following patterns.
1 * * * *
* 2 * * *
* * 3 * *
* * * 4 *
* * * * 5
Java
Java Nested for Loops
17 Likes
Answer
public class KboatPattern
{
public static void main(String args[]) {
char ch = '*';
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= 5 ; j++) {
if(i == j)
System.out.print(i + " ");
else
System.out.print(ch + " ");
}
System.out.println();
}
}
}
Output
Answered By
9 Likes
Related Questions
Write a program to print the series given below.
5 55 555 5555 55555 555555
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.
# * * # # # * * * * # # # # #
Write a program in Java to display the following pattern:
1**** 22*** 333** 4444* 55555