1import java.util.Scanner;
2
3public class ProgrammingEx4_26 {
4 public static void main(String[] args) {
5 // Create a Scanner
6 Scanner input = new Scanner(System.in);
7
8 // Receive the amount
9 System.out.print(
10 "Enter an amount in double, for example 11.56: ");
11 String amount = input.next();
12 int numberOfOneDollars = Integer.parseInt(amount.substring(0, amount.indexOf('.')));
13 int numberOfCents = Integer.parseInt(amount.substring( amount.indexOf('.')+1));
14
15
16
17 // Find the number of quarters in the remaining amount
18 int numberOfQuarters = numberOfCents / 25;
19 numberOfCents = numberOfCents % 25;
20
21 // Find the number of dimes in the remaining amount
22 int numberOfDimes = numberOfCents / 10;
23 numberOfCents = numberOfCents % 10;
24
25 // Find the number of nickels in the remaining amount
26 int numberOfNickels = numberOfCents / 5;
27 numberOfCents = numberOfCents % 5;
28
29 // Find the number of pennies in the remaining amount
30 int numberOfPennies = numberOfCents;
31
32 // Display results
33 System.out.println("Your amount " + amount + " consists of");
34 System.out.println(" " + numberOfOneDollars + " dollars");
35 System.out.println(" " + numberOfQuarters + " quarters ");
36 System.out.println(" " + numberOfDimes + " dimes");
37 System.out.println(" " + numberOfNickels + " nickels");
38 System.out.println(" " + numberOfPennies + " pennies");
39 }
40}
41