forked from TestLeafPages/JavaPrograms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrintingTriangle.java
More file actions
40 lines (35 loc) · 896 Bytes
/
PrintingTriangle.java
File metadata and controls
40 lines (35 loc) · 896 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
package coding;
import org.testng.annotations.Test;
public class PrintingTriangle extends BaseTestNg {
int n = 5;
@Test(priority=1)
public void printingStar() {
int i, j;
// outer loop to handle number of rows
// n in this case
for(i=0; i<n; i++){
// inner loop to handle number of columns
// values changing according to outer loop
for(j=0; j<=i; j++){
// printing stars
System.out.print("* ");
}
// ending line after each row
System.out.println();
}
}
@Test(priority=2)
public void printingReversedStar() {
int i, j, k=n*2-2;
for(i=0; i<n; i++){
for(j=0; j<k; j++){
System.out.print(" ");
}
k = k - 2;
for(j=0; j<=i; j++){
System.out.print("* ");
}
System.out.println();
}
}
}