-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path14.2 Tree Pattern.java
66 lines (50 loc) · 1.41 KB
/
14.2 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
59
60
61
62
63
64
65
66
/*
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”.
Pattern for 2 rows:
&
&&
&&&
Input Format
Program should take the number of rows as input.
Constraints
Entered Number of rows should be positive int value
Output Format
If input is of positive number display the pattern but if input is a negative number or zero, display the message “Invalid Input”.
Sample Input 0
-5
Sample Output 0
Invalid Input
Sample Input 1
2
Sample Output 1
&
&&
*/
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
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 n = sc.nextInt();
if(n>0)
{
for(int i=1;i<=n;i++)
{
int j=1;
while(j++<=i)
{
System.out.print("&");
}
System.out.print("\n");
}
}
else
{
System.out.print("Invalid Input");
}
}
}