題目:某超市店員不諳計算,請您編寫一程式,用於計算在售貨時應該找給顧客的零錢。-------------------- ------------Code Start---------------------public class protect4{
public static void main(String[] args) {
int p=10000,s=2520; //p=支付金額,s=消費金額 int m=p-s; //餘額 int w=m/5000 //伍千元數量 int q=(m-w*5000)/1000; //一千元數量 int wb=(m-w*5000-q*1000)/500; //伍佰元數量 int b=(m-w*5000-q*1000-wb*500)/100; //一百元數量 int ws=(m-w*5000-q*1000-wb*500-b*100)/50; //五十元數量 int t=(m-w*5000-q*1000-wb*500-b*100-ws*50)/10; //十元數量
System.out.println(); System.out.println(); System.out.println("\t顧客支付金額:"+p+"元"); System.out.println("\t顧客消費金額:"+s+"元"); System.out.println(); System.out.println("\t <餘額細目> "); System.out.println("\t餘額:"+m+"元"); System.out.println("\t伍千元:"+w+"張"); System.out.println("\t一千元:"+q+"張"); System.out.println("\t伍佰元:"+wb+"張"); System.out.println("\t一百元:"+b+"張"); System.out.println("\t五十元:"+ws+"張"); System.out.println("\t十 元:"+t+"張"); 餘額細目>
}
}---------------------------------Code ENG----------------------------------執行結果: