import java.text.DecimalFormat;
import java.util.Scanner;
public class DecimalFormatExample
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
double number1;
double number2;
double number3;
System.out.print("Insert first number:");
number1=input.nextInt();
System.out.print("Insert second number:");
number2=input.nextInt();
System.out.print("Insert third number:");
number3=input.nextInt();
DecimalFormat df = new DecimalFormat("0.00");
System.out.println(df.format(number1));
System.out.println(df.format(number2));
System.out.println(df.format(number3));
}}
當我插入例如第一個數字:如何輸入兩位十進制數
Insert first number:1
它會打印出1.00
如果我插入數Insert first number:1.00
,我得到的錯誤。我怎樣才能把小數點插入數字?
尋找替代品'nextInt()' – pamphlet 2014-09-25 15:38:23
試試'nextDouble()'而不是'nextInt()' – user1071777 2014-09-25 15:38:24
感謝您的幫助:D – user3455084 2014-09-25 16:09:36