Skip to content

Commit 828b6a1

Browse files
Create 14.2 Tree Pattern.java
1 parent 9a6119b commit 828b6a1

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

14.2 Tree Pattern.java

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
Alex is very fond of pattern making so he is writing a program to print the pattern of following type .He gives an input of int type which represents the total number of rows and the pattern will be printed up to the entered row size but if Alex enter the negative number ,show “Invalid Input”.
3+
Pattern for 2 rows:
4+
&
5+
&&
6+
&&&
7+
8+
Input Format
9+
10+
Program should take the number of rows as input.
11+
12+
Constraints
13+
14+
Entered Number of rows should be positive int value
15+
16+
Output Format
17+
18+
If input is of positive number display the pattern but if input is a negative number or zero, display the message “Invalid Input”.
19+
20+
Sample Input 0
21+
22+
-5
23+
Sample Output 0
24+
25+
Invalid Input
26+
Sample Input 1
27+
28+
2
29+
Sample Output 1
30+
31+
&
32+
&&
33+
*/
34+
35+
import java.io.*;
36+
import java.util.*;
37+
import java.text.*;
38+
import java.math.*;
39+
import java.util.regex.*;
40+
41+
public class Solution {
42+
43+
public static void main(String[] args) {
44+
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
45+
Scanner sc = new Scanner(System.in);
46+
int n = sc.nextInt();
47+
if(n>0)
48+
{
49+
for(int i=1;i<=n;i++)
50+
{
51+
int j=1;
52+
while(j++<=i)
53+
{
54+
System.out.print("&");
55+
56+
}
57+
System.out.print("\n");
58+
}
59+
}
60+
else
61+
{
62+
System.out.print("Invalid Input");
63+
}
64+
65+
}
66+
}

0 commit comments

Comments
 (0)