1 import java.util.Scanner; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 Scanner input = new Scanner(System.in); 8 9 System.out.print("Enter an amount in int, for example 1156: "); 10 int amount = input.nextInt(); 11 int remainingAmount = amount; 12 input.close(); 13 14 int numberOfOneDollars = remainingAmount / 100; 15 remainingAmount = remainingAmount % 100; 16 17 int numberOfQuarters = remainingAmount / 25; 18 remainingAmount = remainingAmount % 25; 19 20 int numberOfDimes = remainingAmount / 10; 21 remainingAmount = remainingAmount % 10; 22 23 int numberOfNickels = remainingAmount / 5; 24 remainingAmount = remainingAmount % 5; 25 26 int numberOfPennis = remainingAmount; 27 28 System.out.println("Your amount " + amount + " consists of \n" + 29 "\t" + numberOfOneDollars + " dollars\n" + 30 "\t" + numberOfQuarters + " quarters\n" + 31 "\t" + numberOfDimes + " dimes\n" + 32 "\t" + numberOfNickels + " nickels\n" + 33 "\t" + numberOfPennis + " pennis"); 34 } 35 }
时间: 2024-10-09 17:17:31