본문 바로가기
JAVA 코딩 알고리즘 연습/프로그래머스

프로그래머스 - 두 정수 사이의 합 / JAVA (자바) 코딩 알고리즘 연습

by easpop 2023. 2. 9.
728x90
반응형

반응형
class Solution {
    public long solution(int a, int b) {
        long answer = 0;
        
		if(a>b) {
			for (int i = b; i <= a; i++) {
				answer += i;
			}
		}else if(a<b) {
			for (int i = a; i <= b; i++) {
				answer += i;
			}
		}else if(a==b) {
			answer = a;
		}
        
        return answer;
    }
}
728x90
반응형

댓글