-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPattern17whileloop.java
More file actions
50 lines (39 loc) · 1007 Bytes
/
Pattern17whileloop.java
File metadata and controls
50 lines (39 loc) · 1007 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
40
41
42
43
44
45
46
47
48
package com.company;
import java.util.Scanner;
public class Pattern17whileloop {
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 nsp=1;
int nst=rows/2;
while(row<rows){
int cst=0;
while(cst<nst){
System.out.print("*"+" ");
cst++;
}
int csp=0;
while(csp<nsp){
System.out.print(" "+" ");
csp++;
}
cst=0;
while(cst<nst){
System.out.print("*"+" ");
cst++;
}
System.out.println();
if(row<rows/2){
nsp=nsp+2;
nst=nst-1;
}
else {
nsp=nsp-2;
nst=nst+1;
}
row++;
}
}
}