4주차 조건문 & 반복문

조건문

if 문

if(condition){
    // condition이 참(1)일때 실행됨
} else {
    // condition이 거짓(0)일때 실행됨
}
int age = 18; String status;
if (age >= 18) {
	status = "성인"; 
} else {
	status = "미성년자"; 
}
System.out.println("age = " + age + " status = " + status);
         
// 삼항 연산자를 사용하여 간결해진 코드
int age = 18;
String status = (age >= 18) ? "성인" : "미성년자";
System.out.println("age = " + age + " status = " + status);

switch 문

반복문

while 문

while (조건식) { 
	// 코드
}