다음 연산의 결과를 적으시오.

[연습문제] /ch3/Exercise3_1.java

class Exercise3_1 {
  public static void main(String[] args) {
    int x = 2;
    int y = 5;
    char c = 'A'; // 'A' 의 문자코드는 65
    System.out.println(1 + x << 33);
    System.out.println(y >= 5 || x < 0 && x > 2);
    System.out.println(y += 10 - x++);
    System.out.println(x+=2);
    System.out.println( !('A' <= c && c <='Z') );
    System.out.println('C'-c);
    System.out.println('5'-'0');
    System.out.println(c+1);
    System.out.println(++c);
    System.out.println(c++);
    System.out.println(c);
  }
}

 

- System.out.println(c+1);

  + c+1은 정수값이며, 이를 출력하면 66이 된다. 왜냐하면 char + int = int로 자동 형 변환되므로 int가 결과로 도출된다.

- System.out.println(++c);

  + ++c는 char가 되며, 'B'가 된다. 왜냐하면 CPU내에서는 int로 동작되지만 이 값이 char로 저장되어야 하며, 이를 출력하는 것이므로 'B'가 된다.

- System.out.println(c++);

  + c는 'B'이므로 'B'가 출력이 된다. 이후 c는 증가하여 'C'가 된다.

- System.out.println(c);

  + c가 'C'이므로 'C'가 출력된다.

Posted by 세상을 살아가는 사람
,