Computer Applications
Write a program in Java to display the following pattern:
1
35
579
7913
91357
Java
Java Nested for Loops
9 Likes
Answer
public class KboatPattern
{
public static void main(String args[]) {
for (int i = 1, x = 1; i <= 9; i = i+2, x++) {
for (int z = 5; z > x; z--) {
System.out.print(" ");
}
for (int j = i, y = 1; y <= x; j = j+2, y++) {
if (j > 9)
j = 1;
System.out.print(j);
}
System.out.println();
}
}
}
Output

Answered By
6 Likes
Related Questions
What is significance of 'break outer' and 'continue outer' in a nested loop?
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:
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1Write a program in Java to display the following pattern:
AAAAA
BBBB
CCC
DD
E