java.util.Scanner sc = new java.util.Scanner(System.in);
int a = Integer.parseInt(sc.nextLine());
int b = Integer.parseInt(sc.nextLine());
int temp;
temp = a;
a = b;
b = temp;
System.out.println(a);
System.out.println(b);
java.util.Scanner sc = new java.util.Scanner(System.in);
int input = Integer.parseInt(sc.nextLine());
if(input > 10) {
System.out.println("10보다 크다.");
} else {
System.out.println("10보다 크지 않다.");
}
java.util.Scanner sc = new java.util.Scanner(System.in);
int input = Integer.parseInt(sc.nextLine());
if(input > 0) {
System.out.println("양수이다.");
} else if(input == 0) {
System.out.println("0과 같다.");
} else {
System.out.println("음수이다.");
}
java.util.Scanner sc = new java.util.Scanner(System.in);
int a = Integer.parseInt(sc.nextLine());
int b = Integer.parseInt(sc.nextLine());
int c = Integer.parseInt(sc.nextLine());
int tmp;
if(a > b) {
tmp = a;
a = b;
b = tmp;
}
if(a > c) {
tmp = a;
a = c;
c = tmp;
}
if(b > c) {
tmp = b;
b = c;
c = tmp;
}
System.out.println(a);
System.out.println(b);
System.out.println(c);
다음 예제처럼 동작하는지 확인해 보자.
입력값: a, b, c 에 임의수 를 입력받는다.
출력값: a, b, c 값을 출력하면 정렬된 값이 출력된다.
만약에 입력값이 5,1,2이면 출력값은 1,2,5가 된다.
만약에 입력값이 3,7,4이면 출력값은 3,4,7가 된다.
만약에 입력값이 3,5,6이면 출력값은 3,5,6가 된다.