알고리즘/[코드업] 기초3. if ~ else
[JAVA] CodeUp 1172 : 세 수 정렬하기
Art Rudy
2021. 8. 6. 08:53
728x90
반응형
https://codeup.kr/problem.php?id=1172
세 수 정렬하기
세 수를 오름차순으로 정렬하려고 한다. (낮은 숫자 -> 높은 숫자) 예) 5 8 2 ====> 2 5 8 로 출력
codeup.kr
문제 분류 : 기초3. if ~ else
문제 설명
세 수를 오름차순으로 정렬하려고 한다. (낮은 숫자 -> 높은 숫자)
예)
5 8 2 ====> 2 5 8 로 출력
입력
세 정수가 입력된다.
출력
낮은 숫자 부터 출력한다.
입력 예시
8 7 6
출력 예시
6 7 8
도움말
내 답안
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String[] arr = new String[3];
arr = br.readLine().split(" ");
int a = Integer.parseInt(arr[0]);
int b = Integer.parseInt(arr[1]);
int c = Integer.parseInt(arr[2]);
int temp = 0;
if(a >= b) {
temp = b;
b = a;
a = temp;
}
if(b >= c) {
temp = c;
c = b;
b = temp;
}
if(a >= b) {
temp = b;
b = a;
a = temp;
}
bw.write(String.valueOf(a)+" "+String.valueOf(b)+" "+String.valueOf(c));
bw.flush();
bw.close();
br.close();
}
}
728x90
반응형