import java.util.Scanner;
public class Demo5_StringMethod {
/**
*模拟密码输入
*用Scanner接收键盘录入用户名:admin 密码:admin
*三次机会用循环
*输入判断if
*/
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)+"次机会");
}
}
}
}
}
|
|