105 存錢筒

import java.util.*;
public class JPA105 {
    public static void main(String [] args){
String name;
int one;
int five;
int ten;
int fifty;
Scanner sc=new Scanner(System.in);
System.out.print("請輸入您的姓名 :");
name = sc.next();
System.out.println("Hi,"+name+",請輸入您的銅板個數:");
System.out.print("請輸入1元的數量:");
one=sc.nextInt();
System.out.print("請輸入5元的數量:");
five=sc.nextInt();
System.out.print("請輸入10元的數量:");
ten=sc.nextInt();
System.out.print("請輸入50元的數量:");
fifty=sc.nextInt();
int total=one*1+five*5+ten*10+fifty*50;
System.out.print("您的錢總共有:"+(total/1000)+" 千 "+(total/100-(total/1000)*10)+" 百 "+((total%100-(total%10)*10)/10)+" 十 "+(total%10)+" 元");

    }
}

沒有留言:

張貼留言