Skip to content

Commit a381446

Browse files
committedMay 5, 2020
Pattern 25
1 parent 6d0022d commit a381446

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.java.patterns;
2+
import java.util.Scanner;
3+
/*
4+
Write the program to print the following pattern
5+
*
6+
* * *
7+
* * * * *
8+
* * * * * * *
9+
* * * * * * * * *
10+
*/
11+
public class Pattern25 {
12+
public static void main(String args[] ) throws Exception {
13+
Scanner scanner = new Scanner(System.in);
14+
int N = Integer.parseInt(scanner.nextLine());
15+
int iSpace = 0;
16+
int k = 0;
17+
for(int i=0;i<N;i++){
18+
for(int j = iSpace;j<N-1;j++)
19+
System.out.print(" ");
20+
for(int j=0;j<=k;j++)
21+
if(j == 0)
22+
System.out.print("*");
23+
else
24+
System.out.print(" *");
25+
iSpace++;
26+
k+=2;
27+
if(i != N-1)
28+
System.out.println();
29+
}
30+
scanner.close();
31+
}
32+
}
33+
/*
34+
Input
35+
5
36+
Output
37+
*
38+
* * *
39+
* * * * *
40+
* * * * * * *
41+
* * * * * * * * *
42+
*/

0 commit comments

Comments
 (0)