
x++;x+y;(sum>90) ? "A" : "B"
short s = 100;
short result = -s; >> 컴파일 오류
short s = 100l
int result3 = -s; >> OK
x++와 ++x 결과 같음int x = 1;
int y = 1;
int result1 = ++x + 10; >> 연산 전에 X를 1 증가
int result2 = y++ + 10; >> 연산 후에 y를 1 증가
result1 -> 12
result2 -> 11
int x = 10;
int z;
System.out.println("-----------------");
x++;
++x;
System.out.println("x=" + x);
System.out.println("-----------------");
z = x++;
System.out.println("z="+ z); >> z=12
System.out.println("x=" + x); >> x=13
byte v1 = 10;
int v2 = ~v1 + 1; >> -10이 v2에 저장
✅Integer.to.BinaryString() : 정수값을 32비트 이진 문자열로 리턴
>>걍 이진수로 바꿔준다는 뜻임. 막 10101011100010 이런 숫자로.
char c1 = 'A' +1;
char c2 = 'A';
char c3 = c2 + 1; >> 컴파일 오류. 2바이트와 4바이트를 더하면 4바이트 짜리인 int로 받아야 함
char c3 = (char) (c2 +1); >> OK
int x = 1000000;
int y = 1000000;
int z = x + y; >>컴파일 오류
public static void main(String[] args) {
try {
int result = safeAdd(2000000000, 2000000000);
System.out.println(result);
} catch(ArithmeticException e) {
System.out.println("오버플로우가 발생하여 정확하게 계산할 수 없음");
}
}
public static int safeAdd(int left, int right) {
if ( (right>0)) {
if(left>(Integer.MAX_VALUE - right)) {
throw new ArithmeticException("오버플로우 발생");
}
} else {
if (left < (Integer.MIN_VALUE - right)) {
throw new ArithmeticException("오버플로우 발생");
}
}
return left + right;
}
int apple = 1;
double pieceUnit = 0.1;
int number = 7;
double result = apple - number * pieceUnit;
>> 0.299999999999조각
int totalPieces = apple * 10;
int number = 7;
int temp = totalPieces = number;
double result = temp / 10.0;
>> 0.3조각
try {
int z = x + y;
int z = x % y;
System.out.println("Z: " + Z);
} catch (ArithmeticException e) {
System.out.println("0으로 나누면 안됨");
}Double.valueOf("___")는 ____라는 '문자'를 double타입으로 변환 출력함. ∴ double로 받아야함. Double.valueOf("NaN")은 error가 발생하지 않고, double타입에 저장할 수 있는NaN이 나온다. ==는 번지가 같은지를 비교하는 것이기 때문.String strVar1 = "신용권";
String strVar2 = "신용권";
String strVar3 = new String("신용권");
strVar1 == strVar2 -> true
strVar2 == strVar3 -> false
strVar1.equals(strVar2) -> true
strVar2.equals(strVar3) -> true
String str3 = "JDK" + 3 + 3.0; >> JDK33.0
String str4 = 3 + 3.0 + "JDK"; >> 6.0JDK
