-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSumPattern.java
More file actions
48 lines (45 loc) · 1004 Bytes
/
SumPattern.java
File metadata and controls
48 lines (45 loc) · 1004 Bytes
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
// Problem
// Result
// Sum Pattern
// Send Feedback
// 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.Scanner;
public class SumPattern {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
for (int row = 1; row <= n; row++) {
int value = 0;
for (int col = 1; col <= row; col++) {
value += col;
if (col == row) {
System.out.print(col + "=" + value);
} else {
System.out.print(col + "+");
}
}
System.out.println();
}
s.close();
}
}