统计信息

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

p1Q11

2008-01-16 18:56:24

天气: 晴朗 心情: 高兴

  import java.util.Scanner;
 
  public class p1Q11 {
    /** Main method */
    public static void main(String[] args) {
      // Receive the amount
  
       Scanner scan = new Scanner(System.in);
       System.out.println( "Enter an amount in double, for example 11.56: ");
      String amountString = scan.next();
      
 
      // Convert string to double
      double amount = Double.parseDouble(amountString);

      int remainingAmount = (int)(amount * 100);

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

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

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

      // Find the number of nickels in the remaining amount
      int numberOfNickels = remainingAmount / 5;
      remainingAmount = remainingAmount % 5;

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

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

 


加入收藏 编辑 审核

TAG: computing

我来说两句

OPEN

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