2013-05-04 74 views
2
package com.supermarket.project; 
import java.util.Scanner; 
public class Main { 
    public static void main(String[] args) { 
     float amountF; 
     Scanner amount = new Scanner(System.in); 
     System.out.printf("Please enter the amount of purchase: "); 
     amountF = amount.nextFloat(); 
     if (amountF >= 300) { 
      System.out.printf("You amount of purchase is: %1.1f.%n" 
        + "You have a discount of: %1.1f * 90% = %1.1f.%n" 
        + "You can enjoy free delivery service.", amountF, amountF, 
        amountF * 0.9); 
     } else { 
      System.out.printf("Your amount of purchase is: %1.1f.%n" 
        + "Delivery service is available for additional $30.", 
        amountF); 
     } 
    } 
} 

然后我得到了一个错误:异常线程“main” java.util.UnknownFormatConversionException:转换=“”

Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = ' ' 
    at java.util.Formatter.checkText(Formatter.java:2547) 
    at java.util.Formatter.parse(Formatter.java:2523) 
    at java.util.Formatter.format(Formatter.java:2469) 
    at java.io.PrintStream.format(PrintStream.java:970) 
    at java.io.PrintStream.printf(PrintStream.java:871) 
    at com.supermarket.project.Main.main(Main.java:11) 

我应该怎么做来纠正这一错误帮助!当我输入的金额超过300但不低于300时,会出现此错误。我应该怎么做?

+0

为什么你使用'float' JW ......? – Tdorno 2013-05-04 03:39:53

回答

6

"You have a discount of: %1.1f * 90% = %1.1f.%n"

的问题来自于您的90%

将其更改为90%%

+0

谢谢它今天帮助我! – Naeem 2016-03-11 12:08:49

相关问题