import java.util.Scanner;
public class Minimumchange {
public static void main(String[] args)
{
System.out.println("please enter the number of change 1-99");
System.out.println("enter 0 to exit the program");
Scanner Userinput = new Scanner(System.in);
int cntrquart = 0;
int cntrdimes = 0;
int cntrpennies = 0;
int cntrnickels = 0;
//quarters
int chaaching = Userinput.nextInt();
int quarters = chaaching;
while (quarters >= 25)
{
quarters = quarters - 25;
cntrquart = cntrquart + 1;
}
//dimes
int dimes = quarters;
while (dimes >= 10)
{
dimes = dimes - 10;
cntrdimes = cntrdimes + 1;
}
//nickels
int nickels = dimes;
while (nickels >= 5)
{
nickels = nickels - 5;
cntrnickels = cntrnickels + 1;
}
//pennies
int pennies = nickels;
while (pennies >= 1)
{
pennies = pennies - 1;
cntrpennies = cntrpennies + 1;
}
//outputs
System.out.println("mumber of quarters:" + cntrquart);
System.out.println("number of dimes:" + cntrdimes);
System.out.println("number of nickels:" + cntrnickels);
System.out.println("numberof pennies:" + cntrpennies);
System.out.println("Thank you for using Dark Alley Development");
}
}
用户输入 1-99,我的程序会告诉您制作 x 所需的硬币、硬币、镍币和便士的最小数量。我希望程序一遍又一遍地运行,直到用户输入 0。