스마트 인재개발원/Java

2021-04-14 자바 로그인만들기 (스마트인재개발원)

앨런튜링_ 2021. 4. 14. 14:16
package day2;

import java.util.Scanner;

public class ex24로그인만들기2 {

	public static void main(String[] args) {
		Scanner sc  = new Scanner(System.in);
		
		String user_id = "Hello";
		
		String user_pass = "1234";
		
		while(true) {
			
			System.out.print("아이디를 입력해주세요 :");
			String input_id = sc.next();
			
			if (user_id.equals(input_id))
			{
				System.out.print("비밀번호를 입력해주세요 :");
				String input_pass = sc.next();
				
				if (input_pass.equals(user_pass)) {
					
					System.out.println("로그인 되었습니다.");
				}
				else {
					System.out.print("비밀번호가 틀렸습니다. 다시 하시겠습니까?");
					String input_result = sc.next();
					
					if(input_result.equals("Y")){
						
						continue;
					}
					else {
						System.out.println("프로그램이 종료 되었습니다.");
						break;
				}
				
				
			 }
			}else {
				System.out.print("아이디가 틀렸습니다. 다시 하시겠습니까?");
				String input_result = sc.next();
				
				if(input_result.equals("Y")){
					
					continue;
				}
				else {
					System.out.println("프로그램이 종료 되었습니다.");
					break;
				}						
				
			}
			
		}
				 						
	}

}
​
package day2;

import java.util.Scanner;

public class ex23로그인만들기 {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		String User_id = "Hello";
		String User_pass = "1234";
		
		while(true) {
			System.out.print("아이디를 입력해 주세요 :");
			String input_user_id = sc.next();
	
			
			if(User_id.equals(input_user_id)) {
				System.out.print("비밀번호를 입력해 주세요 :");
				String input_user_pass = sc.next();
				
				if(User_pass.equals(input_user_pass)) {
					System.out.println("로그인되었습니다.");
					
				}else {
					System.out.println("비밀번호가 틀렸습니다. ");
				}
				
			}else {
				System.out.println("아이디가 틀렸습니다. ");
		
			}
			
		}

	}

}