공부/JAVA_source
자바 큰값 작은값 비교
초초이
2016. 10. 24. 19:49
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | /* * 두 개의 정수를 입력받아 큰값과 작은 값을 출력하는 프로그램을 구현하시오. * <입력형식> * 첫번째수 = * 두번째수 = * * <출력형식> * 큰수 = * 작은수 = * */ import java.io.*; public class Exam_02 { public static void main(String[] ar) throws IOException{ int first, second, third, max, min; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.print("첫번째수 = "); first = Integer.parseInt(in.readLine()); System.out.print("두번째수 = "); second = Integer.parseInt(in.readLine()); System.out.print("세번째수 = "); third = Integer.parseInt(in.readLine()); if(first > second && first > third){ max = first; if(second > third){ min = third; }else{ min = second; } }else if(second > first && second > third){ max = second; if(first > third){ min = third; }else{ min = first; } }else{ max = third; if(first > second){ min = second; }else{ min = first; } } System.out.println(); System.out.println("큰수 = " + max); System.out.println("작은수 = " + min); } } | cs |