Skip to content

Commit b5a08ba

Browse files
Create 13.1 Tree Pattern.java
1 parent 6ca47ba commit b5a08ba

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

13.1 Tree Pattern.java

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
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:
3+
4+
1
5+
2 3
6+
4 5 6
7+
7 8 9 10
8+
11 12 13 14 15
9+
16 17 18 19 20 21
10+
11+
Input Format
12+
13+
The input should be taken as row number.
14+
15+
Constraints
16+
17+
row number should be positive>0
18+
19+
Output Format
20+
21+
It should print “Invalid rows” if the input taken is zero 0r less than zero.
22+
23+
Sample Input 0
24+
25+
4
26+
Sample Output 0
27+
28+
1
29+
2 3
30+
4 5 6
31+
7 8 9 10
32+
*/
33+
import java.io.*;
34+
import java.util.*;
35+
36+
public class Solution {
37+
38+
public static void main(String[] args) {
39+
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
40+
Scanner sc = new Scanner(System.in);
41+
int row = sc.nextInt();
42+
if(row>0)
43+
{
44+
int value = 1;
45+
for(int i=1;i<=row;i++)
46+
{
47+
for(int j=1;j<=i;j++)
48+
System.out.print(value++ +" ");
49+
System.out.print("\n");
50+
}
51+
}
52+
else
53+
{
54+
System.out.print("Invalid rows");
55+
}
56+
57+
}
58+
}

0 commit comments

Comments
 (0)