1 import javax.swing.JOptionPane; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 String amountString = JOptionPane.showInputDialog(null, "Enter an amount in int, for example 1156: ", 8 "Input Amount", JOptionPane.QUESTION_MESSAGE); 9 int amount = Integer.parseInt(amountString); 10 int remainingAmount = amount; 11 12 int numberOfOneDollars = remainingAmount / 100; 13 remainingAmount = remainingAmount % 100; 14 15 int numberOfQuarters = remainingAmount / 25; 16 remainingAmount = remainingAmount % 25; 17 18 int numberOfDimes = remainingAmount / 10; 19 remainingAmount = remainingAmount % 10; 20 21 int numberOfNickels = remainingAmount / 5; 22 remainingAmount = remainingAmount % 5; 23 24 int numberOfPennis = remainingAmount; 25 26 String output = "Your amount " + amount + " consists of \n" + 27 "\t" + numberOfOneDollars + " dollars\n" + 28 "\t" + numberOfQuarters + " quarters\n" + 29 "\t" + numberOfDimes + " dimes\n" + 30 "\t" + numberOfNickels + " nickels\n" + 31 "\t" + numberOfPennis + " pennis"; 32 33 JOptionPane.showMessageDialog(null, output); 34 } 35 }
时间: 2024-11-05 13:09:56