- import java.util.Scanner;
- public class LoginTest
- {
- private static final String ACCOUNT="lindatao";
- private static final String PASSWORD="123456";
-
- public static void main(String[] args)
- {
- for(int i=1; i<=3; i++)
- {
- Scanner sc =new Scanner(System.in);
- System.out.println("请输入账号:");
- String account = sc.nextLine();
- System.out.println("请输入密码:");
- String passWord = sc.nextLine();
-
- if(account.equals(ACCOUNT) && passWord.equals(PASSWORD))
- {
- System.out.println("登入成功!");
- return;
- }
- else
- {
- System.out.println("密码或者账号错误"+i+"次");
- }
- if(i>=3)
- {
- System.out.println("密码或者账号错误超过3次,退出程序!");
- System.exit(0);
- }
- }
-
- }
- }
复制代码 |