본문 바로가기

프로그래머스

프로그래머스 - 두 정수 사이의 합

class Solution {
public long solution(int a, int b) {
long answer = 0;
int tmp;

if (a > b) {
tmp = a;
a = b;
b = tmp;
}

while (a <= b) {
answer += a;
a++;
}

return answer;
}
}