- import java.util.Scanner;
- class DengLu {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- for(int i = 2; i >= 0; i--) {
- System.out.println("请输入用户名:");
- String userName = sc.nextLine();
- System.out.println("请输入密码:");
- String password = sc.nextLine();
- if("admin".equals(userName) && "admin".equals(password)) {
- System.out.println("欢迎" + userName + "登录");
- break;
- }else {
- if(i == 0) {
- System.out.println("您的错误次数已到,请明天再来吧");
- }else {
- System.out.println("登录错误,您还有" + i + "次机会");
- }
- }
- }
- }
- }
复制代码 |
|