문제 & 예시
소스코드
// 두 정수 사이의 합
public class test26 {
public static void main(String[] args) {
Solution26 sol = new Solution26();
int a = 3;
int b = 5;
System.out.println(sol.solution(a, b));
}
}
class Solution26 {
public long solution(int a, int b) {
long answer = 0;
// a보다 b가 큰경우
// b보다 a가 큰경우
// a와 b가 같은 경우
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;
}
}