연산자 종류
[기초연산자]
대입연산자
x = 1
산술연산자
코드 | 출력값 |
public class test { public static void main(String[] args) { int a = 100; int result = a - 1; System.out.println(result); //99 result -= 1; System.out.println(result); //98 result *= 2; System.out.println(result); //196 result /= 2; System.out.println(result); // 98 result %= 2; System.out.println(result); // 0 } } |
99 98 196 98 0 |
비교연산자 (관계연산자) / 논리연산자
코드 | 출력값 |
public class test { public static void main(String[] args) { System.out.println(1==2); System.out.println(1==1); System.out.println("one"=="two"); System.out.println("one"=="one"); System.out.println('\n'); System.out.println(1!=2); System.out.println(1!=1); System.out.println("one"!="two"); System.out.println("one"!="one"); System.out.println('\n'); System.out.println(10>20); System.out.println(10>2); System.out.println(10>10); |
false true false true true false true false false true false |
댓글