-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPattern18.java
More file actions
39 lines (33 loc) · 908 Bytes
/
Pattern18.java
File metadata and controls
39 lines (33 loc) · 908 Bytes
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
package com.company;
import java.util.Scanner;
public class Pattern18 {
public static void main(String[] args) {
System.out.print("Enter the number of rows with while:");
Scanner sc = new Scanner(System.in);
int rows = sc.nextInt();
int row = 0;
int nst = 1;
int nsp = rows / 2;
while (row < rows) {
int csp = 0;
while (csp < nsp) {
System.out.print(" " + " ");
csp++;
}
int cst = 0;
while (cst < nst) {
System.out.print("*" + " ");
cst++;
}
System.out.println();
if (row < rows / 2) {
nsp = nsp - 1;
nst = nst + 2;
} else {
nsp = nsp + 1;
nst = nst - 2;
}
row++;
}
}
}