비교 연산자와 문자열의 비교
비교 연산자
비교 연산자
설명
class Operator6_1 {
public static void main(String[] args) {
int n1 = 10, n2 = 6;
char c1 = 'A', c2 = 'B';
System.out.print("n1 >= n2 = " ); // true
System.out.println(n1 >= n2);
System.out.print("n1 <= n2 = " ); // false
System.out.println(n1 <= n2);
System.out.print("n1 == n2 = " ); // false
System.out.println(n1 == n2);
System.out.print("n1 != n2 = " ); // true
System.out.println(n1 != n2);
// 산술변환 규칙에 의해서 char 타입이 int 타입으로 변환되어 연산됨
System.out.print("c1 < c2 = "); // true
System.out.println(c1 < c2); // 65 < 66
System.out.print("c1 > c2 = "); // false
System.out.println(c1 > c2); // 65 > 66
}
}문자열의 비교
문자열 비교에는 == 대신 equals()를 사용해야 합니다.
Last updated