본문 바로가기
개인공부

연산자 (대입/산술/비교/논리)

by 리승우 2022. 7. 13.

연산자 종류

[기초연산자]

대입연산자

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

 

 

'개인공부' 카테고리의 다른 글

반복문의 중첩  (0) 2022.07.15
반복문의 제어  (0) 2022.07.14
반복문  (0) 2022.07.14
조건문  (0) 2022.07.13
변수의 데이터타입, 형변환(암시적,명시적)  (0) 2022.07.13

댓글