FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java_Fundamentals/RectangularNumber.java at main · devdeepak06/Java_Fundamentals · GitHub
devdeepak06
/
Java_Fundamentals
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java_Fundamentals
/
RectangularNumber.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
98 lines (84 loc) · 2.3 KB
Breadcrumbs
Java_Fundamentals
/
RectangularNumber.java
Copy path
File metadata and controls
98 lines (84 loc) · 2.3 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//Print the following pattern for the given number of rows.
//Pattern for N = 4
//4444444
//4333334
//4322234
//4321234
//4322234
//4333334
//4444444
//Input format :
//Integer N (Total no. of rows)
//Output format :
//Pattern in N lines
//Constraints :
//0 <= N <= 50
//Sample Input 1:
//3
//Sample Output 1:
//33333
//32223
//32123
//32223
//33333
import
java
.
util
.
Scanner
;
public
class
RectangularNumber
{
public
static
void
print
(
int
n
) {
//Write your code here
int
s
=
2
*
n
-
1
;
// Upper Half
for
(
int
i
=
0
;
i
< (
s
/
2
) +
1
;
i
++)
{
int
m
=
n
;
// Decreasing part
for
(
int
j
=
0
;
j
<
i
;
j
++)
{
System
.
out
.
print
(
m
);
m
--;
}
// Constant Part
for
(
int
k
=
0
;
k
<
s
-
2
*
i
;
k
++)
{
System
.
out
.
print
(
n
-
i
);
}
// Increasing part.
m
=
n
-
i
+
1
;
for
(
int
l
=
0
;
l
<
i
;
l
++)
{
System
.
out
.
print
(
m
);
m
++;
}
System
.
out
.
println
();
}
// Lower Half
for
(
int
i
=
s
/
2
-
1
;
i
>=
0
;
i
--)
{
// Decreasing Part
int
m
=
n
;
for
(
int
j
=
0
;
j
<
i
;
j
++)
{
System
.
out
.
print
(
m
);
m
--;
}
// Constant Part.
for
(
int
k
=
0
;
k
<
s
-
2
*
i
;
k
++)
{
System
.
out
.
print
(
n
-
i
);
}
// Decreasing Part
m
=
n
-
i
+
1
;
for
(
int
l
=
0
;
l
<
i
;
l
++)
{
System
.
out
.
print
(
m
);
m
++;
}
System
.
out
.
println
();
}
}
public
static
void
main
(
String
[]
args
) {
try
(
Scanner
scanner
=
new
Scanner
(
System
.
in
)) {
int
n
=
scanner
.
nextInt
();
print
(
n
);
}
}
}
Back
|
FazBrowse Home
|
New Git URL