- 資訊首頁(yè) > 開(kāi)發(fā)技術(shù) >
- JAVA如何實(shí)現賬戶(hù)取款和存款操作
這篇文章給大家分享的是有關(guān)JAVA如何實(shí)現賬戶(hù)取款和存款操作的內容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。
JAVA 編寫(xiě)一個(gè)程序完成從某賬戶(hù)取款和存款的操作
(1)輸入存款金額是,如果非數值型,捕獲一場(chǎng)并進(jìn)行處理
(2)操作賬戶(hù)類(lèi)是,如果取款金額大于余額時(shí)則做異常處理
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("****當前賬戶(hù)余額:"+residue+"****"); System.out.println("1.存錢(qián) 2.取錢(qián) 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; } } }}
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。
Copyright ? 2009-2022 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 特網(wǎng)科技 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 百度云 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站