當前位置:編程學習大全網 - 編程軟體 - 要求用戶輸入1元,5元,10元的張數,以元為單位輸出所有錢的總和的編程怎麽寫

要求用戶輸入1元,5元,10元的張數,以元為單位輸出所有錢的總和的編程怎麽寫

import java.util.Scanner;

public class test{

public static void main(String[] args) {

int yiYuan,wuYuyan,shiYuan,total;

System.out.print("請輸入壹元的張數:");

yiYuan = new Scanner(System.in).nextInt();

while(yiYuan < 0){

System.out.println("數量必須大於0,請重新輸入!");

System.out.println("");

System.out.print("請輸入壹元的張數:");

yiYuan = new Scanner(System.in).nextInt();

}

System.out.print("請輸入五元的張數:");

wuYuyan = new Scanner(System.in).nextInt();

while(wuYuyan < 0){

System.out.println("數量必須大於0,請重新輸入!");

System.out.println("");

System.out.print("請輸入五元的張數:");

wuYuyan = new Scanner(System.in).nextInt();

}

System.out.print("請輸入十元的張數:");

shiYuan = new Scanner(System.in).nextInt();

while(shiYuan < 0){

System.out.println("數量必須大於0,請重新輸入!");

System.out.println("");

System.out.print("請輸入十元的張數:");

shiYuan = new Scanner(System.in).nextInt();

}

total = yiYuan + 5 * wuYuyan + 10 * shiYuan;

System.out.println("妳輸入的壹元有:" + yiYuan +"張,五元有:"

+ wuYuyan +"張,十元有:" + shiYuan + "張,總金額是:" + total +"元.");

}

}

  • 上一篇:學編程哪個軟件快?
  • 下一篇:無語言編程
  • copyright 2024編程學習大全網