코딩응급실
프로그래머스: 나머지가 1이 되는 수 찾기 본문
class Solution {
public int solution(int n) {
int answer = 1;
while(true) {
if (n%answer==1) break;
answer++;
}
return answer;
}
public static void main(String[] args) {
int n = 12;
Solution sol = new Solution();
int result = sol.solution(n);
System.out.println(result);
}
}
'Java' 카테고리의 다른 글
프로그래머스: 부족한 금액 계산하기 (0) | 2024.01.20 |
---|---|
프로그래머스: 없는 숫자 더하기 (0) | 2024.01.20 |
프로그래머스: 신고 결과 받기 (0) | 2024.01.20 |
프로그래머스: 성격 유형 검사하기 (1) | 2024.01.20 |
프로그래머스: 숫자 짝꿍 (0) | 2024.01.20 |