50,526
社区成员
发帖
与我相关
我的任务
分享
public class JavaTest {
private final static String pwd = "111111";
private final static Integer max_money = 1000;
public static void main(String[] args) throws Exception {
String password = "";
int errorCount = 0;
do {
System.out.print("请输入密码:");
Scanner scanner = new Scanner(System.in);
password = scanner.next();
if (!pwd.equals(password)) {
errorCount++;
if (errorCount >= 3) {
break;
} else {
continue;
}
}
Integer money = null;
do {
if (money == null) {
System.out.print("请输入金额:");
money = scanner.nextInt();
} else {
System.out.print("金额不正确,请重新输入:");
money = scanner.nextInt();
}
} while (money > max_money || money < 0 || money % 100 != 0);
System.out.println("您取走了" + money + "元!");
} while (!pwd.equals(password) || errorCount >= 3);
if (errorCount < 3) {
System.out.println("交易完成,请取卡");
} else {
System.out.println("密码错误,请取走卡");
}
}
}