JAVA制御文-boolean、比較演算子


boolean


booleanデータ型にはtrue、falseの2つのデータがあり、真または偽を区別します.
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
	}
} 
  • containsメソッドは、入力した文字列に存在する値に基づいてtrueまたは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
    	}
    }