JAVA 제어문 - boolean, 비교연산자

황찬호·2021년 4월 6일
0

Java1

목록 보기
8/14

boolean

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
	}
} 
  • 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
	}
}
profile
되는대까지 해보기

0개의 댓글