
난이도: ★☆☆☆☆ • solved on: 2025-07-12

multiple", factor", neither"자료구조
int형 변수, 문자열 배열알고리즘/기법
핵심 키워드
- 문제 분해
- 무한 루프(while true)로 입력을 반복적으로 받음
- 한 줄 입력을 split하여 두 수를 int로 변환
- a==0 && b==0이면 루프 종료
- a가 b의 배수면 "multiple" 출력
b가 a의 배수면 "factor" 출력
아니면 "neither" 출력- 핵심 로직 흐름
while (입력 반복) { if (a == 0 && b == 0) break; if (a % b == 0) "multiple" else if (b % a == 0) "factor" else "neither" }- 예외 처리
- 종료 조건(a==0 && b==0)만 명확히 확인
import java.util.*;
import java.lang.*;
import java.io.*;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while(true){
String[] line = br.readLine().split(" ");
int a = Integer.parseInt(line[0]);
int b = Integer.parseInt(line[1]);
if(a==0&&b==0){
break;
}
if(a%b == 0){
System.out.println("multiple");
} else if(b%a == 0){
System.out.println("factor");
} else {
System.out.println("neither");
}
}
}
}
split으로 받은 String을 int로 바꾸는 과정과, char형을 int로 변환하는 방법이 다름을 정확히 구분해야 한다.int intFromString = Integer.parseInt(stringInput);
int intFromChar = (int) charInput;
비슷한 유형(GPT 추천):
확장 문제(GPT 추천):