본문 바로가기
프로그래머스/Java

공배수

by HoPpangg 2023. 5. 24.
SMALL

문제)

정수 number와 n,m이 주어집니다.

number가 n의 배수이면서 m의 배수이면 1을 아니라면 0을 return하도록 soulution 함수를 완성해주세요.

 

제한사항

  • 1 <= number <= 100
  • 2 <= n,m < 10

입출력 예

number n m result
60 2 3 1
55 10 5 0

 

 

class Solution {
    public int solution(int number, int n, int m) {
        int answer = 0;
        if(number%n == 0 && number%m ==0){
            answer = 1;
        }
        return answer;
    }
}
class Solution {
    public int solution(int number, int n, int m) {
        int answer = number%n == 0 && number%m == 0 ? 1 : 0;
        return answer;
    }
}
728x90
LIST

'프로그래머스 > Java' 카테고리의 다른 글

더 크게 합치기  (0) 2023.05.24
문자열 반복해서 출력하기  (0) 2023.05.24
문자 리스트를 문자열로 변환하기  (0) 2023.05.24

댓글