본문 바로가기
IT/Java

Java (If else문 예제2_정수 값 3개 순서대로 출력)

by hjshims 2021. 4. 8.

정수 값 3개를 입력 받아 큰 수부터 순서대로 출력

 

package P0408;

import java.util.Scanner;

public class IfTemp2 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		
		int first, second, third, temp;
		
		System.out.print("첫번째 수: ");
		first = scan.nextInt();
		System.out.print("두번째 수: ");
		second = scan.nextInt();
		System.out.print("세번째 수: ");
		third = scan.nextInt();
		
		if(first<second) {  
			temp = first;
			first = second;
			second = temp;
		}
		if(first<third) { 
			temp = first;
			first = third;
			third = temp;
		}
		if(second<third) { 
			temp = second;
			second = third;
			third = temp;
		}
		
		System.out.println(first + " >= " + second + " >= " + third);
		
	}

}