-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatterns1.java
More file actions
73 lines (64 loc) · 2.48 KB
/
Copy pathPatterns1.java
File metadata and controls
73 lines (64 loc) · 2.48 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
import java.util.Scanner;
public class Patterns1 {
// Function to print a pattern of stars in a right-angled triangle
public static void pat1(int n) {
for (int i = 1; i <= n; i++) { //used to control the number of rows
for (int j = 1; j <= i; j++) { //used to control the number of stars in each row
System.out.print("* ");
}
System.out.println();
}
}
// Function to print a pattern of stars in an inverted right-angled triangle
public static void pat2(int n) {
for (int i = 1; i <= n; i++) { //used to control the number of rows
for (int j = 1; j <= n - i + 1; j++) { //used to control the number of stars in each row
System.out.print("* ");
}
System.out.println();
}
}
// Function to print a pattern of NUMBERS in a right-angled triangle
public static void pat3(int n) {
for (int i = 1; i <= n; i++) { //used to control the number of rows
for (int j = 1; j <= i; j++) { //used to control the number of stars in each row
System.out.print(j);
}
System.out.println();
}
}
// Function to print a pattern of ALPHABETS in a right-angled triangle
public static void pat4(int n) {
char ch = 'A';
for (int i = 1; i <= n; i++) { //used to control the number of rows
for (int j = 1; j <= i; j++) { //used to control the number of characters in each row
System.out.print(ch);
ch++;
}
System.out.println();
}
}
//INVERTED & ROTATED HALF-PYRAMID pattern
public static void pat5(int n) {
for (int i = 1; i <= n; i++) { //used to control the number of rows
for (int j = 1; j <= n-i; j++) { //used to control the number of space in each row
System.out.print(" ");
}
for (int j = 1; j <= i; j++) { //used to control the number of stars in each row
System.out.print("*");
}
System.out.println();
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter value of N: ");
int n = sc.nextInt();
sc.close();
// pat1(n);
// pat2(n);
// pat3(n);
// pat4(n);
pat5(n);
}
}