- import java.util.Scanner;
- public class Test2_1 {
- /**
- * 模拟用户登录
- */
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.println("请设置您的用户名:");
- final String userName = sc.nextLine();
- System.out.println("请设置你的密码:");
- final String password = sc.nextLine();
- System.out.println("您的账户已经申请完毕,用户名是" + userName);
- for (int i = 0; i < 3; i++) {
- System.out.println("请输入您的用户名:");
- String thisName = sc.nextLine();
- System.out.println("请输入您的密码:");
- String thispassword = sc.nextLine();
- if (userName.equals(thisName) && password.equals(thispassword)) {
- System.out.println("您好,欢迎" + userName + "登录");
- break;
- } else {
- if (i == 2) {
- System.out.println("登录次数已经用完,明天同一时间我们再见");
- } else {
- System.out.println("登录失败,请检查您的账户密码是否正确" + ",您还有" + (2 - i)
- + "次机会");
- }
- }
- }
- }
- }
复制代码 |
|