// 파일 이름: NestedIfExample.java
public class NestedIfExample {
public static void main(String[] args) {
int score = 85;
if (score >= 60) {
System.out.println("합격입니다.");
if (score >= 90) {
System.out.println("우수한 성적입니다.");
} else {
System.out.println("좀 더 노력해봅시다.");
}
} else {
System.out.println("불합격입니다.");
}
}
}
score >= 60
→ 합격 기준score >= 90
→ "우수"합격입니다.
좀 더 노력해봅시다.
(점수가 85니까 합격은 맞지만, 우수는 아님)
String username = "admin";
String password = "1234";
if (username.equals("admin")) {
if (password.equals("1234")) {
System.out.println("로그인 성공");
} else {
System.out.println("비밀번호가 틀렸습니다.");
}
} else {
System.out.println("존재하지 않는 사용자입니다.");
}