[Programmers] 두 정수 사이의 합 - 연습문제

동민·2021년 3월 10일
0
// 두 정수 사이의 합 - 연습문제
public class Sumof2N {

	public long solution(int a, int b) {

		long sum = 0;

		for (int i = Math.min(a, b); i <= Math.max(a, b); i++) {
			sum += i;
		} 

		return sum;

	}

	public static void main(String[] args) {
		Sumof2N s = new Sumof2N();
		System.out.println(s.solution(3, 3));
	}

}
profile
BE Developer

0개의 댓글

관련 채용 정보

Powered by GraphCDN, the GraphQL CDN