연산자 == 은 왼쪽 항과 오른쪽 항이 같으면 true 값이 되고

연산자 !=은 왼쪽 항과 오른쪽 항이 다르면 true 값이 됩니다.

연산자 &&는 왼쪽과 오른쪽이 모두 true 값이면 true이고

연산자 ||는 왼쪽과 오른쪽 중 하나만 true 값이어도 true가 됩니다.

다음 코드를 통해서 확인해보겠습니다.


public class ExTest {

public static void main(String[] args) {

int x=8;

int y=3;

boolean b1 = x==8 && y==3;

boolean b2 = x==8 && y==1;

boolean b3 = x==8 || y==1;

boolean b4 = x!=7;

System.out.println(b1);

System.out.println(b2);

System.out.println(b3);

System.out.println(b4);

}

}


다음은 실행결과입니다.




+ Recent posts