21.06.09 - 생활코딩 JAVA 공부

·2021년 6월 28일
0

생활코딩JAVA

목록 보기
7/12

1. 제어문 - Boolean

public class BooleanApp {

	public static void main(String[] args) {
		
		System.out.println("One");
		System.out.println(1);
		
		//boolean의 두가지 데이터타입
		System.out.println(true);
		System.out.println(false);
		
		String foo = "Hello world";
		// String true = "Hello world"; true,false는 변수 이름으로 사용할 수 없다.
		// reserved word 라고 부른다.
		
		System.out.println(foo.contains("world")); // foo변수 안에 "world" 포함됨 = true
		System.out.println(foo.contains("minju")); // foo변수 안에 "minju" 포함안됨 = false
		
	}

}

2. 제어문 - 비교연산자

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
		
		
	}

}

3. 제어문 - 조건문(형식)

public class IfApp {

	public static void main(String[] args) {
		
		System.out.println("a");
		if(false) {
			System.out.println(1); //dead code = 실행되지 않는 코드
		}
		System.out.println("b");

	}

}
public class IfApp {

	public static void main(String[] args) {
		
		System.out.println("a");
		if(false) {
			System.out.println(1);
		}
		else if(true) {
			System.out.println(2);
			} else {
				System.out.println(3);
			}
	
		System.out.println("b");

	}

}

0개의 댓글