第八章練習題

Duanhaifeng55發表於2018-04-08

//ATM取錢模擬

public static void ATM() {

int password = 0;// 密碼
int amount = 0;// 金額
System.out.print("請輸入密碼:");
Scanner input = new Scanner(System.in);
password=input.nextInt();
while (password != 111111) {
System.out.print("密碼不正確,請重新輸入密碼:");
Scanner input2 = new Scanner(System.in);
password = input2.nextInt();
}
System.out.print("請輸入金額:");
Scanner input3 = new Scanner(System.in);
amount=input3.nextInt();
while (amount > 1000 && amount >= 0) {
System.out.print("您輸入的金額不合法,請重新輸入金額:");
Scanner input2 = new Scanner(System.in);
amount=input2.nextInt();
}
System.out.println("您取了:"+amount);
System.out.println("交易完成,請取卡");
}

相關文章