JAVA
조건문 연습 (5) - if문 로그인(id/pw)
선우진우
2023. 12. 29. 21:06
728x90
반응형
public void practice5() {
/* 아이디, 비밀번호를 정해두고 로그인 기능을 작성하세요.
로그인 성공 시 “로그인 성공”,
아이디가 틀렸을 시 “아이디가 틀렸습니다.“,
비밀번호가 틀렸을 시 “비밀번호가 틀렸습니다.”를 출력하세요.
*/
//ex 1. ex 2. ex 3.
//아이디 : myId 아이디 : myId 아이디 : my
//비밀번호 : myPassword12 비밀번호 : myPassword 비밀번호 : myPassword12
//로그인 성공 비밀번호가 틀렸습니다. 아이디가 틀렸습니다.
Scanner sc = new Scanner(System.in);
System.out.print("아이디 : ");
String input1 = sc.nextLine();
System.out.print("비밀번호 : ");
String input2 = sc.nextLine();
String id = "myId";
String pw = "myPassword12";
String result = null;
if(input1.equals(id) && input2.equals(pw)) {
result = "로그인 성공!";
}else if(input1.equals(id) && !input2.equals(pw)) {
result = "비밀번호가 틀렸습니다.";
}else if(!input1.equals(id) && input2.equals(pw)) {
result = "아이디가 틀렸습니다.";
}else
result = "다시 확인 해주세요."; {
}
System.out.println(result);
}

728x90
반응형