public class lec0322_1 {
public static void main(String[] args) {
//산술연산
int a = 120, b = 'c';
/// 단항
System.out.println(a++);
System.out.println(++a);
int x = a++ - ++a; //
System.out.println(x);
// 사칙과 나머지
int c = a / b;
int d = a % b;
System.out.println(a + "," + b + "," + c + "," + d);
byte i = 10, j = 2;
byte k = (byte)(i + j);
a = 1_000_000;
long t = a * (2 * a);
System.out.println(t);
// 비트연산(정수만 됨)
a = 120;
int e = a << 2;
int f = a >> 5;
System.out.println(Integer.toBinaryString(a));
System.out.println(Integer.toBinaryString(e));
System.out.println(Integer.toBinaryString(f));
int m = 0b1011_0101;
System.out.println(Integer.toBinaryString(m & 0b1111));
System.out.println(Integer.toBinaryString(m | 0b1111));
a=3; b=4; c=4;
System.out.println(a^b^c);
System.out.println(Integer.toBinaryString(~m));
}
}
import java.util.*;
import java.lang.*;
public class App {
public static void main(String[] args) throws Exception {
//후위 연산자는 증감 전의 값을 반영한 후 증감을 하고 전위 연산자는 증감을 먼저 하여 값을 반영하기 때문에 x의 값은 7-(1+1+7)인 -2이다.
int a = 7;
int x = a++ - ++a;
System.out.println(x);
}
}
import java.util.*;
import java.lang.*;
public class App {
public static void main(String[] args) throws Exception {
int a = 7;
int x = a++ - ++a; // 후위연산자는 연산이 끝난 후 a값에 +1을 하고, 전위연산자는 +1을 먼저 하기 때문에 7 - (8+1) = -2 이다.
System.out.println(x);
}
}