标签:
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 11.56: "); 10 double amount = input.nextDouble(); 11 int remainingAmount = (int)(amount * 100); 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 if(numberOfOneDollars != 0) 30 System.out.println("\t" + numberOfOneDollars + " dollars"); 31 if(numberOfQuarters != 0) 32 System.out.println("\t" + numberOfQuarters + " quarters"); 33 if(numberOfDimes != 0) 34 System.out.println("\t" + numberOfDimes + " dimes"); 35 if(numberOfNickels != 0) 36 System.out.println("\t" + numberOfNickels + " nickels"); 37 if(numberOfPennis != 0) 38 System.out.println("\t" + numberOfPennis + " pennis"); 39 } 40 }
标签:
原文地址:http://www.cnblogs.com/wood-python/p/5762894.html