연습문제를 풀어보며 헷갈렸던 개념과 오답노트를 작성해보았습니다.
byte b = 10;
char ch = 'A';
int i = 100;
long l = 1000L;
a. b = (byte)i;
b. ch = (char)b;
c. short s = (short)ch;
d. float f = (float)l;
e. i = (int)ch;
✅ d, e
맞았지만 e가 확실하지 않았었음
d, e
❌ 0~256
0~65535
a. byte b = 256;
b. char c = '';
c. char answer = 'no';
d. float f = 3.14;
e. double d = 1.4e3f;
❌ a, c, d
a, b, c, d
a. public static void main(String[] args)
b. public static void main(String args[])
c. public static void main(String[] arv)
d. public void static main(String[] args)
e. static public void main(String[] args)
❌ a, b
a, b, c, e
a. public static void main(String[] args) // a와 b는 배열 선언 방식 차이
b. public static void main(String args[])
c. public static void main(String[] arv) // 매개변수 이름은 중요하지 않음
d. public void static main(String[] args) // void는 main 앞에 와야 함
e. static public void main(String[] args) //
char ch = 'A'+ 1 // 65 + 1 = 66, 66은 ch에 담을 수 있으므로 'B'로 자동 형변환
char ch = 'A' + 1000 // 1065는 ch에 담을 수 없으므로 컴파일 에러 발생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);
}
}
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); // true
System.out.println(y += 10 - x++); // 13
System.out.println(x+=2); // 5
System.out.println(!('A' <= c && c <= 'z')); // false
System.out.println('C' - c); // 2
System.out.println('5' - '0'); // 5
System.out.println(c+1); // 66
System.out.println(++c); // 66
System.out.println(c++); //66
System.out.println(c); // 67
}
}

조건문과 반복문, 그리고 배열부분은 틀린 것이 없었지만 자료형과 연산자 부분에서 문제가 있었습니다. 'IDE가 해주니까 그냥 넘겨버리자', '뭐 대충 다 아는데' 이런 생각으로 넘겼던 부분입니다. 이번 계기를 통해 기초를 튼튼히 공부하자 라는 마음가짐을 되새기게 되었습니다.