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
55 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
19 Likes
Related Questions
Write a program in Java to find the sum of the following series:
S = 1 + (3/2!) + (5/3!) + (7/4!) + ……. to n
Write a program in Java to display the following pattern:
1
3 1
5 3 1
7 5 3 1
9 7 5 3 1What is significance of 'break outer' and 'continue outer' in a nested loop?
Write a program in Java to display the following pattern:
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1