package com.heima.test;
import java.util.Scanner;
public class Demo_login {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
for (int i = 0; i < 3; 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 == 2) {
System.out.println("机会已经用完了,请明天再来!");
}else{
System.out.println("用户名或是密码错误,还剩 " + (2-i)+ "次");
}
}
}
}
}
|
|