-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatterns.java
More file actions
51 lines (51 loc) · 1.58 KB
/
Copy pathPatterns.java
File metadata and controls
51 lines (51 loc) · 1.58 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
import java.util.Scanner;
public class Patterns {
static int n;
static void p1() {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
System.out.print("* "); }
System.out.println(); }}
static void p2() {
for(int i=1; i<=n; i++)
{ for(int j=1; j<=i; j++)
{ System.out.print(j+" "); }
System.out.println(); }}
static void p3() { //floyd's triangle
int num=1;
for(int i=1; i<=n; i++)
{ for(int j=1; j<=i; j++)
{ System.out.print(num + " ");
num++; }
System.out.println(); }
}
static void p4() {
for(int i=1; i<=n; i++)
{ char ch=(char)('A'+i);
for (int j=0; j<=i; j++)
{ System.out.print(ch); }
System.out.println(); }
}
static void p5() {
for (int i = 0; i < n; i++) {
int num = 1;
System.out.print(" ".repeat((n - i) * 2));
for (int j = 0; j <= i; j++) {
System.out.print(num + " ");
num = num * (i - j) / (j + 1); } //pascal's triangle
System.out.println();}
}
public static void main(String[] args) {
System.out.println("Enter the number of rows: ");
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
p1();
System.out.println();
p2();
System.out.println();
p3();
System.out.println();
p4();
System.out.println();
p5(); }
}