-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatern2.java
More file actions
54 lines (37 loc) · 854 Bytes
/
Patern2.java
File metadata and controls
54 lines (37 loc) · 854 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
write a program to display the following output
* * * * *
* * * *
* * *
* *
*
*/
import java.util.Scanner;
class Patern2
{
public static void Patern2(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 k=1; k<=n-i+1; k++)
{
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
Patern2 pt = new Patern2();
pt.Patern2(number);
}
}