-
Notifications
You must be signed in to change notification settings - Fork 0
/
Patern3.java
61 lines (41 loc) · 963 Bytes
/
Patern3.java
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
/*
write a program to display the following output
*
* *
* * *
* * * *
* * * * *
*/
import java.util.Scanner;
class Patern3
{
public static void Patern3(int n)
{
// Outer loop to handle number of rows
for(int i=1;i<=n;i++)
{
// inner loop to handle number of columns
for(int j=1;j<=n; j++)
{
for(int k=1; k<=n-i+1; k++)
{
System.out.print(" ");
}
System.out.print("*");
}
// ending line after each row
System.out.println();
}
}
// main method to get input from user
public static void main (String args[])
{
// First import Scanner from java.util. Create object of Scanner class
Scanner in = new Scanner(System.in);
System.out.println("enter number :");
int number = in.nextInt();
//create object of patern class
Patern3 pt = new Patern3();
pt.Patern3(number);
}
}