import java.util.Scanner;
//课本38页, 2-10;
public class ComputeChange {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
//Receive the amount
System.out.print(
"Enter an amount in double, for example 11.56:");
double amount = input.nextDouble();
int remainingAmount = (int)(amount * 100);
//find the number of one dollers
int numberOfOneDollars = remainingAmount / 100;
remainingAmount = remainingAmount % 100;
//Find the number of dimes in the remaining amount
int numberOfQuarters = remainingAmount / 25;
remainingAmount = remainingAmount % 25;
//Find the number of dimes in the remaining amount
int numberOfDimes = remainingAmount / 10;
remainingAmount = remainingAmount % 10;
//Find the of nickls in the remaining amount
int numberOfNickels = remainingAmount / 5;
remainingAmount = remainingAmount % 5;
//Find the number if pennies in the remaining amount
int numberOfPennies = remainingAmount;
//Disply results
System.out.println("Your amount " + amount + " consists of \n" +
"\t" + numberOfOneDollars + " dollars\n" +
"\t" + numberOfQuarters + "quarters\n" +
"\t" + numberOfDimes + "dimes\n" +
"\t" + numberOfNickels + " nickels\n" +
"\t" + numberOfPennies + " pennies");
}
}
(每日一java)ComputeChange
最新推荐文章于 2024-06-06 17:04:03 发布