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

HW2.10

时间:2016-08-07 10:55:43      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

 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 }

 

HW2.10

标签:

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

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