统计信息

  • 访问数:14529
  • 博客数:143
  • 建立时间:2008-01-05
  • 更新时间:2008-10-15
我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!

p1Q10

2008-01-16 18:30:29

天气: 晴朗 心情: 高兴

 import javax.swing.JOptionPane;

 public class p1Q10 {
   /** Main method */
   public static void main(String[] args) {
     // Receive the amount
     String amountString = JOptionPane.showInputDialog(
       "Enter an amount in int, for example the input 1156 represents 11 dollars and 56 cents");

      // Convert string to int
      int amount = Integer.parseInt(amountString);


      // Find the number of one dollars
      int numberOfOneDollars = amount / 100;
      amount = amount % 100;

      // Find the number of quarters in the remaining amount
      int numberOfQuarters = amount / 25;
      amount = amount % 25;

      // Find the number of dimes in the remaining amount
      int numberOfDimes = amount / 10;
      amount = amount % 10;


      int numberOfNickels = amount / 5;
      amount = amount % 5;

      // Find the number of pennies in the remaining amount
      int numberOfPennies = amount;

      // Display results
        String output = "Your amount " + amount + " consists of \n" +
        numberOfOneDollars + " dollars\n" +
        numberOfQuarters + " quarters\n" +
        numberOfDimes + " dimes\n" +
        numberOfNickels + " nickels\n" +
        numberOfPennies + " pennies";
      JOptionPane.showMessageDialog(null, output);
   }
 }


加入收藏 编辑 审核

TAG: computing

我来说两句

OPEN

Powered by X-Space 1.2 © 2001-2006 Comsenz Technology Ltd