삼항연산

    삼항 연산자

    삼항 연산자 조건식의 결과 값에 따라 연산을 처리하는 연산자 조건식이 참일 경우 식1을 실행, 거짓일 경우 식2를 실행 삼항 연산자 중첩 사용 가능 짝수, 홀수 확인 public void method1() { int nInput = 0; String sResult = ""; Scanner s = new Scanner(System.in); System.out.printf("Input Number(e.g. 3): "); nInput = s.nextInt(); sResult = (nInput % 2 == 0) ? "EVEN" : "ODD"; System.out.printf("%d is \"%S\"\n", nInput, sResult); } 결과값 Input Number(e.g. 3): 100 100 is "E..