- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSumBetweenTwoNum.java
More file actions
Latest commit
22 lines (19 loc) · 726 Bytes
/
Copy pathSumBetweenTwoNum.java
File metadata and controls
22 lines (19 loc) · 726 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
packagedev.solar.level1;
importjava.util.stream.LongStream;
publicclassSumBetweenTwoNum {
publiclongsolution(inta, intb) {
intmin = Math.min(a, b);
intmax = Math.max(a, b);
longanswer = LongStream.rangeClosed(min, max).sum();
returnanswer;
}
publicstaticvoidmain(String[] args) {
SumBetweenTwoNumtest = newSumBetweenTwoNum();
longresult = test.solution(3,3);
System.out.println(result);
}
}
/*
두 값을 Math클래스의 min(), max() 메서드로 작은 값, 큰 값을 구분하여 (min, max) 순서로 넘겨준다.
Long타입의 Stream을 열어서 rangeClosed(min, max) min부터 max(포함)까지의 값을 sum() 해준다.
*/