비교연산자
두 피연산자를 비교해서 true(참) 또는 false(거짓)을 반환
대소비교 연산자
비교 연산자 | 연산결과 |
> | 좌변 값이 크면, true,아니면 flase |
< | 좌변 값이 작으면, true 아니면 flase |
>= | 좌변 값이 크거나 같으면, true 아니면 flase |
<= | 좌변 값이 작거나 같으면, true 아니면 flase |
public class practice {
public static void main(String[] args) {
System.out.println(1>0); // true
System.out.println(1<0); // false
System.out.println(1>=1); // true
System.out.println(1<=1); // true
}
}
산술변환 ②번
public class practice {
public static void main(String[] args) {
System.out.println('A'>='B'); // 65 >= 66 -> false
}
}
등가 비교 연산자
비교연산자 | 연산결과 |
== | 두 값이 같으면, true 아니면 false |
!= | 두 값이 다르면, true 아니면 false |
public class practice {
public static void main(String[] args) {
System.out.println(2 == 2); // true
System.out.println(2 == 3); //false
System.out.println(2 != 2); // false
System.out.println(2 != 3); // true
}
}
반응형
'이것이 자바다 > JAVA1' 카테고리의 다른 글
조건 연산자 ? : (0) | 2023.05.17 |
---|---|
문자열 비교 equals() (0) | 2023.05.16 |
나머지 연산자 % (0) | 2023.05.16 |
반올림, Math.round() (0) | 2023.05.16 |
산술 변환 (0) | 2023.05.15 |