-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathSumPattern.java
68 lines (59 loc) · 1.19 KB
/
SumPattern.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
67
68
/*
Write a program to print triangle of user defined integers sum.
Input Format :
A single integer, N
Output Format :
Required Pattern
Constraints :
0 <= N <= 50
Sample Input 1 :
3
Sample Output 1 :
1=1
1+2=3
1+2+3=6
Sample Input 2 :
5
Sample Output 2 :
1=1
1+2=3
1+2+3=6
1+2+3+4=10
1+2+3+4+5=15
*/
import java.util.*;
import java.lang.*;
public class SumPattern {
public static void main(String[] args) {
// Write your code here
Scanner scan = new Scanner(System.in);
int N=scan.nextInt();
outer_loop:for(int i=1;i<=N;i++)
{
int sum=1;
if (i==1)
{
System.out.println("1=1");
continue outer_loop;
}
else
{
System.out.print("1+");
}
inner:for (int j=2;j<=i;j++)
{
sum=sum+(j);
System.out.print(j);
if (j<i)
{
System.out.print("+");
}
else
{
System.out.println("="+sum);
break inner;
}
}
}
}
}