Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6a18c38

Browse filesBrowse files
NumericDiamondPattern is added
1 parent a75c5d5 commit 6a18c38
Copy full SHA for 6a18c38

File tree

1 file changed

+51
-0
lines changed
Filter options

1 file changed

+51
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package Pattern.NumberPattern;
2+
3+
public class NumericDiamondPattern {
4+
public static void main(String[] args) {
5+
int n = 4, count = 0;
6+
for (int i = 1; i <= n; i++) {
7+
for (int j = i; j < n; j++) {
8+
System.out.print(" ");
9+
}
10+
11+
count+=i;
12+
for (int j = 1; j <= i; j++) {
13+
14+
System.out.print(count+" ");
15+
if(j<i) count--; else count+=i-1;
16+
}
17+
System.out.println();
18+
}
19+
20+
for (int i = 1; i <= n; i++) {
21+
for (int j = 1; j < i; j++) {
22+
System.out.print(" ");
23+
}
24+
25+
for (int j = i; j <= n; j++) {
26+
System.out.print(count+" ");
27+
count--;
28+
}
29+
30+
System.out.println();
31+
}
32+
}
33+
}
34+
35+
// Input:
36+
// n = 4
37+
38+
// Output:
39+
// 1
40+
// 3 2
41+
// 6 5 4
42+
// 10 9 8 7
43+
// 10 9 8 7
44+
// 6 5 4
45+
// 3 2
46+
// 1
47+
48+
// Explaination:
49+
// First upperTriangle like reverse number printing
50+
// Add the row value to count value minus each columns when last column is reached then
51+
// add current count with row value - 1 (to reach the initial value)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.