Computer Applications
Write a program in Java to display the following pattern:
1234554321
1234 4321
123 321
12 21
1 1
Java
Java Nested for Loops
42 Likes
Answer
public class KboatNumberPattern
{
public static void main(String args[]) {
for (int i = 5, x = 0; i >= 1; i--, x += 2) {
for (int j = 1; j <= i; j++) {
System.out.print(j);
}
for (int y = 1; y <= x; y++) {
System.out.print(' ');
}
for (int k = i; k >= 1; k--) {
System.out.print(k);
}
System.out.println();
}
}
}
Output
Answered By
16 Likes