-
Notifications
You must be signed in to change notification settings - Fork 2
/
13.1 Tree Pattern.java
58 lines (45 loc) · 1.16 KB
/
13.1 Tree Pattern.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
/*
write a code that accepts an input of integer type, which represents the number of rows to display the Floyds Triangle pattern upto 6 rows. Display “invalid rows” without a pattern if the input given is negative:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
Input Format
The input should be taken as row number.
Constraints
row number should be positive>0
Output Format
It should print “Invalid rows” if the input taken is zero 0r less than zero.
Sample Input 0
4
Sample Output 0
1
2 3
4 5 6
7 8 9 10
*/
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc = new Scanner(System.in);
int row = sc.nextInt();
if(row>0)
{
int value = 1;
for(int i=1;i<=row;i++)
{
for(int j=1;j<=i;j++)
System.out.print(value++ +" ");
System.out.print("\n");
}
}
else
{
System.out.print("Invalid rows");
}
}
}