-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest4.java
More file actions
34 lines (31 loc) · 777 Bytes
/
Copy pathTest4.java
File metadata and controls
34 lines (31 loc) · 777 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
package programmers;
public class Test4 {
public long solution(int a, int b) {
long answer = 0;
if (a < b) {
for (int i = a; i <= b; i++) {
answer += i;
}
} else if (a > b) {
for (int i = b; i <= a; i++) {
answer += i;
}
}else{
answer = a;
}
return answer;
}
public static void main(String[] args) {
Test4 sumNum = new Test4();
System.out.println(sumNum.solution(3, 5));
}
}
//class Solution {
// public long solution(int a, int b) {
// long answer = 0;
// for (int i = ((a < b) ? a : b); i <= ((a < b) ? b : a); i++)
// answer += i;
//
// return answer;
// }
//}