62,621
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args ) throws InterruptedException{
Scanner input = new Scanner(System.in);
System.out.println("请输入你的密码:");
int i= 0;
while (true) {
String password = input.next();
if (!"123456".equals(password)) {
System.out.println("error");
System.out.println("请输入你的密码:");
i++;
if (i%3 == 0) {
System.out.println("对不起你已连续输错3次密码,请稍后再试");
// Thread.sleep(4000);
// System.out.println("请输入你的密码:");
// 也可直接跳出
break;
}
} else {
System.out.println("right");
break;
}
}
}
if(password!="123456") 改成 if (!"123456".equals(password))
格式木有调好,楼主将就看吧
public static void main(String[] args ){
Scanner input = new Scanner(System.in);
System.out.println("请输入你的密码:");
int i= 0;
while (true) {
String password = input.next();
if (!"123456".equals(password)) {
System.out.println("error");
i++;
if (i == 3) {
System.out.println("对不起你输入的次数大于3次,稍后再试");
}
// continue;
} else {
System.out.println("right");
break;
}
}
}