欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JAVA實(shí)現(xiàn)賬戶取款和存款操作

 更新時間:2019年11月26日 10:55:56   作者:沃德吉爾·邦英  
這篇文章主要介紹了JAVA實(shí)現(xiàn)賬戶取款和存款操作,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下

這篇文章主要介紹了JAVA實(shí)現(xiàn)賬戶取款和存款操作,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下

JAVA 編寫一個程序完成從某賬戶取款和存款的操作

(1)輸入存款金額是,如果非數(shù)值型,捕獲一場并進(jìn)行處理

(2)操作賬戶類是,如果取款金額大于余額時則做異常處理

import java.util.Scanner;

public class Blank {
  public static void main(String[] args) {
    float residue = 10000.0f;
    String type;
    Scanner scn = new Scanner(System.in);
    while(true) {
      System.out.println("****當(dāng)前賬戶余額:"+residue+"****");
      System.out.println("1.存錢 2.取錢 0.退出");
      System.out.print("請選擇(1,2,0):");
      type = scn.nextLine();
      if(type.equals("1")) {
        System.out.print("請輸入金額:");
        try {
          int money = scn.nextInt();
          residue = money+residue;
        } catch (Exception e) {
          // TODO: handle exception
          System.out.println("輸入錯誤...");
          scn.nextLine();
        }
      }
      else if(type.equals("2")) {
        try {
          System.out.print("請輸入:");
          int money = scn.nextInt();
          if(money>residue) {
            throw new Exception();
          } else {
            residue = residue-money;
          }
        } catch (Exception e) {
          // TODO: handle exception
          System.out.println("余額不足");
          scn.nextLine();
        }
      }
      
      else if(type.equals("0")) {
        System.out.println("bye..");
        break;
      }
    }
    
  }
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論