즐거운프로그래밍

[자바] 노트패드++ 제어문 if

수수께끼 고양이 2023. 10. 10. 14:04
728x90
반응형

1. if : 판단하기 1

public class MainApp {
	public static void main(String args[]) {
    	int age=23;
		if(age>=19) { // 이면
			System.out.println("adult");
		}
	}
}

 

2. if~else : 판단하기 2

public class MainApp {
	public static void main(String args[]) {
    	int age=23;
		if(age>=19) { // 이면
			System.out.println("adult");
		} else { // 그렇지 않으면, else는 무조건 if와 함께 함
			System.out.println("minor");
		}
	}
}

 

3. if~else, if~else : 판단하기 3

public class MainApp {
	public static void main(String args[]) {
    int birth_year=2004;
		if(birth_year>=1981 && birth_year<=1996) {
			System.out.println("M generation");
		} else if(1997<=birth_year && birth_year<=2009) {
			System.out.println("Z generation");
		} else if(2010<=birth_year && birth_year<=2025) {
			System.out.println("Alpha generation");
		} else {
			System.out.println("???");
		}
	}
}

 

728x90
반응형