zoukankan      html  css  js  c++  java
  • ATM机的代码(作业)

    import java.util.Scanner;

    public class ATMDemo {
     /**
      * 简单ATM机取款过程模拟
      */
     public static void main(String[] args) {
      String pass = ""; // 保存用户输入密码
      int amount = 0; // 取款金额
      String password = "111111"; // 用户密码
      int count = 0; // 记录密码输入次数
      boolean isPass = false; // 密码是否通过验证
      Scanner input = new Scanner(System.in);

      while (count < 3 && !isPass) {
       System.out.print("请输入密码:");
       pass = input.next();
       if (!password.equals(pass)) {
        count++;
        continue;
       }
       isPass = true; // 密码通过验证
       System.out.print("请输入金额:");
       amount = input.nextInt();
       while (amount > 0) {
        if (amount <= 1000 && amount % 100 == 0) {
         System.out.println("您取了" + amount + "元");
         System.out.println("交易完成,请取卡!");
         break; // 完成交易,退出
        } else {
         System.out.print("您输入金额的金额不合法,请重新输入:");
         amount = input.nextInt();
         continue; // 继续让用户输入金额
        }
       }
      }
      if (!isPass) { // 用户输入了3次错误密码
       System.out.print("密码错误,请取卡!");
      }
     }
    }

  • 相关阅读:
    django模型系统(二)
    css基础
    css进阶
    django模型系统(一)
    自定义过滤器及标签
    django模板标签
    模板变量及模板过滤器
    第六章 异常
    第三章:多态
    第三章:提高系统性能:从数据访问开始
  • 原文地址:https://www.cnblogs.com/LWLDD/p/6697442.html
Copyright © 2011-2022 走看看