i got stuck at below pattern, seeking any help on it.
i can’t able to write proper code for bottom part using ternary operators, i have seen many other code available in diff format, however i wanna do it with ternary ops.
Any help is more appreciable.
i/p n=5
Expected output
12345
2345 ===upper part
345
45
5
45
345
2345
12345
output i got:
1 2 3 4 5
2 3 4 5
3 4 5
4 5
5
6 7
7 8
8 9 ===bottom part
9 10
10 11
I have tried to solve it using ternary operator but no luck
static void pattern(int n) {
for (int i = 1; i <= 2 * n; i++) {
int colInRows = i <= n ? n : (i + 1);
int spacesInRows = i <= n? 1: (i - n)+2;
for (int j = i ; j > spacesInRows ; j--) {
System.out.print(" ");
}
for (int k=i ; k <= colInRows ; k++){
System.out.print(k + " ");
}
System.out.println();
}
}
1