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