【程式語言】JAVA的第三堂課 |找錢系統 make change money
Published:
by .import java.util.Scanner;
public class ch4
{
public static void main(String[] arg)
{
int money , fifty , ten , five , one;
Scanner scn= new Scanner(System.in);
System.out.print("Input the amount for change:");
money = scn.nextInt();
fifty = money / 50;
ten = (money - (50*fifty))/10;
five = (money - ((50*fifty) + (10*ten)))/5;
one = (money - ((50*fifty) + (10*ten) + (five*5)));
System.out.println("50's:" + fifty);
System.out.println("10's:" + ten);
System.out.println("5's:" + five);
System.out.println("1's:" + one);
}
}