-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPattern32.java
More file actions
50 lines (34 loc) · 914 Bytes
/
Pattern32.java
File metadata and controls
50 lines (34 loc) · 914 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
49
50
package com.company;
import java.util.Scanner;
public class Pattern32 {
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 nstn=1;
int val=1;
while(row<((2*rows)-1)){
int cst=0;
while(cst<nstn) {
if (cst % 2 == 0) {
System.out.print(val+" ");
} else {
System.out.print("*"+" ");
}
cst++;
}
//preparation
System.out.println();
if(row<((2*rows)-1)/2){
nstn=nstn+2;
val++;
}
else{
nstn=nstn-2;
val--;
}
row++;
}
}
}