import java.util.Scanner;
public class AuthApp3 {
public static void main(String[] args) {
String[] users = { "karina", "winter" , "ning" } ;
System.out.print("Your name?: ");
Scanner in = new Scanner(System.in) ;
String inputId = in.next() ;
boolean isLogined = false;
for ( int i = 0 ; i < users.length ; i++ ) {
String currentId = users[i] ;
if (currentId.equals(inputId)) {
isLogined = true ;
break ;
}
}
if ( isLogined ) {
System.out.println("Hi! " + inputId );
} else {
System.out.println("WRONG USER!!");
}
}
}
import java.util.Scanner;
public class AuthApp3 {
public static void main(String[] args) {
String[][] users = {
{"karina", "1111" },
{"winter", "2222" },
{"ning", "3333" }
} ;
System.out.print("Your name?: ");
Scanner in = new Scanner(System.in) ;
String inputId = in.next() ;
System.out.print("Password?: ");
String inputPass = in.next() ;
boolean isLogined = false;
for ( int i = 0 ; i < users.length ; i++ ) {
String [] current = users[i] ;
if (
current[0].equals(inputId) &&
current[1].equals(inputPass)
) {
isLogined = true ;
break ;
}
}
if ( isLogined ) {
System.out.println("Hi! " + inputId );
} else {
System.out.println("WRONG USER or PASSWORD!!");
}
}
}
import java.util.Scanner;
public class AuthApp_pr2 {
public static void main(String[] args) {
String[][] users = { { "karina", "1111" }, { "winter", "2222" }, { "ning", "3333" } };
// users 입력 받기
Scanner in = new Scanner(System.in);
System.out.print("Id?: ");
String inputId = in.next();
System.out.print("Password?: ");
String inputPw = in.next();
// users, 비밀번호 맞는지 반복문, 조건문
boolean isRightId = false;
boolean isRightPw = false;
for (int i = 0; i < users.length; i++) {
String[] current = users[i];
boolean isId = inputId.equals(current[0]);
boolean isPw = inputPw.equals(current[1]);
if (isId && isPw) {
isRightId = true;
isRightPw = true;
break;
} else if (isId) {
isRightId = true;
}
}
if ( isRightId && isRightPw ) {
System.out.println("Welcome! " + inputId);
} else if ( isRightId ) {
System.out.println("WRONG PW!!");
} else {
System.out.println("WRONG ID!!");
}
}
}