File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ Write a program to print N number of rows for Half Diamond pattern using stars and numbers
3+ Note : There are no spaces between the characters in a single line.
4+ */
5+
6+ import java .util .Scanner ;
7+
8+ public class Half_Diamond_Pattern {
9+ public static void main (String [] args ) {
10+ // Write your code here
11+ Scanner sc = new Scanner (System .in );
12+ int n = sc .nextInt ();
13+ System .out .println ("*" );
14+ for (int i = 1 ; i <= n ; i ++)
15+ {
16+ int j = 1 ;
17+ System .out .print ("*" );
18+ while (j <= i )
19+ {
20+ System .out .print (j );
21+ j ++;
22+ }
23+ j --;
24+ while (--j >= 1 )
25+ {
26+ System .out .print (j );
27+ }
28+ System .out .println ("*" );
29+ }
30+ for (int i = n - 1 ; i >= 1 ; i --)
31+ {
32+ int j = 1 ;
33+ System .out .print ("*" );
34+ while (j <= i ) {
35+ System .out .print (j );
36+ j ++;
37+ }
38+ j --;
39+ while (--j >= 1 )
40+ {
41+ System .out .print (j );
42+ }
43+ System .out .println ("*" );
44+ }
45+ System .out .println ("*" );
46+
47+ }
48+ }
You can’t perform that action at this time.
0 commit comments