-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShapedTower.java
More file actions
95 lines (81 loc) · 1.94 KB
/
ShapedTower.java
File metadata and controls
95 lines (81 loc) · 1.94 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package com.company;
import java.util.Scanner;
public class ShapedTower {
public int i; // Declare value distance
// Method build Right Triangle
public void builRightTriangle(int n)
{
int i=1;
while (i<=n)
{
for(int j=1;j<=i;j++)
{
System.out.print(" *");
}
System.out.println();
i++;
}
}
// Method build Right Triangle 2
public void builRightTriangle2(int n)
{
i=n;
while (i>=1)
{
for(int j=1;j<=i;j++)
{
System.out.print(" *");
}
System.out.println();
i--;
}
}
// Method build left Triangle
public void builLeftTriangle(int n)
{
i=1;
while (i<=n)
{
for(int k=1;k<=(n-i);k++)
{
System.out.print(" ");
}
for(int j=1;j<=i;j++)
{
System.out.print("* ");
}
System.out.println();
i++;
}
}
// Method buil Isosceles Triangle
public void IsoscelesTriangle(int n)
{
i=1;
while (i<=n)
{
for(int k=1;k<=(n-i);k++)
{
System.out.print(" ");
}
for(int j=1;j<=(2*i-1);j++)
{
System.out.print("* ");
}
System.out.println();
i++;
}
}
public static void main(String[] args) {
Scanner input =new Scanner(System.in);
ShapedTower test1=new ShapedTower();
System.out.println("Please input value of Distance: ");
int n =input.nextInt();
test1.IsoscelesTriangle(n);
System.out.print("\n");
test1.builLeftTriangle(n);
System.out.print("\n");
test1.builRightTriangle2(n);
//test1.builRightTriangle(n);
}
}