结果为什么不对呢 字符串比较,用equals!"123456".equals(password) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 if (!password .equals("123456"))这样写 你这里怎么能用!=比较2个字符串呢比较字符串要用equals 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; } }} if(password!="123456") 改成 if (!"123456".equals(password)) 突然发现这个挺好玩的,哈哈,可以让休息几秒钟接着输,也可以直接跳出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))i==3 改成i%3=0或者在if里将i置为0 if (!password .equals("123456")) JAVA卜能用了?这种情况该怎么办? 搞不懂的问题,希望有人能详细讲解一下 关于在java程序中编译和运行另一个java程序的问题? 遇到不懂,求教:不能在applet中现实面板 sql 中获取_下划线后的内容。 有人能够告诉我散分3000的方法吗? 有没有办法在线程的run()里面改变外面的类的变量的值,有例子 发布Applet出现的错误,帮忙撒 你是怎样分类package your java class? 用com.sun.java.swing 里的japplet 代替 原来的applet是不是可以啊??? 算法问题 java 员工考勤代码设计
这样写
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;
}
}
}
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;
}
}
}
i==3 改成i%3=0或者在if里将i置为0