Java 更改应用

Java change app

所以我一直在开发一个程序,距离我上次使用 java 已经有一段时间了。我想知道如何让我的程序接受小数。我已经尝试查找它,但我找不到任何有用的东西,我真正 understood.Below 是我到目前为止所做的...

    package test;
    import java.util.Scanner;

    /**
     *
     * @author Thao
     */
    public class Test {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
    // TODO code application logic here
    // create Scanner to obtain input from command window
    Scanner input = new Scanner( System.in );
    double cash; // double makes it allow decimals
    int hundred;
    int twenty;
    int ten;
    int toonies ;
    int lonies;
    int quarters;
    int dimes;
    int nickels;
    int pennies;
    int money;
    int change;

    System.out.println();// blank line
    System.out.print("Hello ");
    System.out.println();
    System.out.println("Please enter a number with no decimal places ");
    cash = input.nextInt(); // read first integer
    System.out.println("you have Entered "+cash);
    hundred = 100; 
    change = (int)hundred - (int)cash; 
    System.out.println("The change from 0.00 is:" + (double)change);


    change = 100 * change; // multiply  cash by 100
    money = (int)change; //cash is now a int

     twenty = money / 2000; 
     money = money - (twenty * 2000); 

    toonies = money / 200; // money is multiplied by 100 than / by 200
     money = money - (toonies * 200); // ex. money =  1586 - (7.93 * 200 )

    lonies = money / 100 ; 
     money = money - (lonies * 100);

    quarters = money / 25;
     money = money - (quarters * 25);

    dimes = money / 10;
     money = money - (dimes * 10);

    nickels =  money / 5; 
     money = money - (nickels * 5);

    pennies = money / 1;
     money = money - (pennies * 1);
    if(twenty>0){
    System.out.println();
    System.out.print("You will have this many Twenties ");
    System.out.print(twenty + "."); 
    }
    else{
    }
    if(toonies>0){
    System.out.println();
    System.out.print("You will have this many Toonies ");
    System.out.print(toonies + ".");
    System.out.println();
    }
    else{
    }
    if(lonies>0){
    System.out.print(" You will have this many Lonies ");
    System.out.print(lonies + ".");
    System.out.println();
    }
    else{
    }
    if(quarters>0){
    System.out.print(" You will have this many quarters ");
    System.out.print(quarters + ".");
    System.out.println();
    }
    else{
    }

    if(dimes>0){
    System.out.print(" You will have this many dimes ");
    System.out.print(dimes + ".");
    System.out.println();
    }
    else{
    }

    if(dimes>0){
    System.out.print(" You will have this many nickels ");
    System.out.print(nickels);
    System.out.println();
    }
    else{
    }
    if(pennies>0){
    System.out.print(" You will have this many pennies ");
    System.out.print(pennies);
    System.out.println();
    }
    else{
    }
    System.out.println();
    System.out.println("Thank you for using my app ");


    }
    }

您可以使用 double 或 float 作为变量的数据类型。要从您的输入中读取 double,您可以这样做:

double cash = input.nextDouble();

float cash = input.nextFloat();