要图形界面还是命令行的?
import java.io.Console;
import java.util.Random;
public class User {
public static void main(String[] args) {
Console console = System.console();
for(int i = 3; i > 0; --i){
String username = console.readLine("Please input your name:");
char[] password = console.readPassword("Please input your password:");
if(verifyUser(username,password)){
System.out.printf("你输入了正确的
用户名和密码,可以进入系统。%n");
break;
} else {
System.out.printf("用户名或密码输入有误,你还有%d次机会从新输入.%n", i-1);
}
}
}
private static boolean verifyUser(String username,char[] password){
// 仅作演示,根据需要修改
return new Random().nextBoolean();
}
}