공부/JAVA_source
[자바] 두개의 수 입력받아 큰 수 출력 (두개의 수 비교/삼항연산자)
초초이
2016. 10. 24. 19:45
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 | /* * 두 개의 숫자를 입력받아 큰 수를 출력하는 프로그램을 구현하시오. * 단, 삼항연산자를 사용하여 구현할 것. * <입력형식> * 첫번째수 = xx * 두번째수 = xx * * <출력형식> * 큰수 : xx * */ import java.io.*; public class Exam_12 { public static void main(String[] ar) throws IOException{ // 선언문 BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int first, second, third, max; // 입력문 System.out.print("첫번째수 = "); first = Integer.parseInt(in.readLine()); System.out.print("두번째수 = "); second = Integer.parseInt(in.readLine()); System.out.print("세번째수 = "); third = Integer.parseInt(in.readLine()); // 처리문 or 출력문 max = second > first? second : first; max = third > max? third: max; System.out.println("큰수 : " + max); } } | cs |