연산자(Operator) 정의
증감 연산자
// 증감연산자 ++, --
int x = 10;
//int y = x++; // y = x; x = x + 1;
int y = ++x; // x = x + 1; y = x;
System.out.println("x = " + x);
System.out.println("y = " + y);
// -> x = 11
// -> y = 11
산술 연산자
int x = 1234;
System.out.println("x % 7 = " + (x % 7));
// 0 ~ 6 사이의 값을 반환
System.out.println("x % 2 = " + (x % 2));
// 0 ~ 1 사이의 값을 반환, x값이 홀수인지 짝수인지 구분에 유용
// -> x % 7 = 2
// -> x % 2 = 0
비교 연산자
// 비교연산자 <, >, <=, >=, ==, !=
int x = 12;
int y = 15;
// boolean bool = x > y;
// boolean bool = x < y;
boolean bool = (x = x + 5) != y;
System.out.println("bool = " + bool);
// -> bool = true
논리 연산자
// 논리연산자 &, |, !, &&, ||
int x = 20;
int y = 30;
boolean bool;
bool = x < y || (x = x + 15) > y;
System.out.println("bool = " + bool);
System.out.println("x = " + x);
// -> bool = true
// -> x = 20
대입 연산자