码迷,mamicode.com
首页 > 其他好文 > 详细

HW3.7

时间:2016-08-11 22:32:34      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

 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 }

 

HW3.7

标签:

原文地址:http://www.cnblogs.com/wood-python/p/5762894.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!