boolean이라는 데이터 타입안에는 true, false 두가지 데이터가 존재하는데 참 또는 거짓을 구분할때 쓰인다.
public class BooleanApp {
public static void main(String[] args) {
String foo = "Hello world";
// ture와 false같은 컴퓨터언어에서 쓰임이 있는 단어는 변수로 사용불가능(reserved word라고 함)
// String true = "Hello world";
System.out.println(foo.contains("world")); //true
System.out.println(foo.contains("egoing")); //false
}
}
비교연산자는 왼쪽에 있는 값과 오른쪽에 있는 값을 비교하여 결과에 따라 true 또는 false를 출력한다.
< , > , == , >=, <= 와 같은 기호들이 있다.
public class ComparisonOperatorApp {
public static void main(String[] args) {
System.out.println(1 > 1); //false
System.out.println(1 == 1); //true
System.out.println(1 < 1); //false
System.out.println(1 >= 1); //true
}
}