所以这是我写的代码,我不确定错误在哪里,所以也许你们可以提供帮助..
import java.util.Scanner;
public class Discount {
public static void main(String[] args){
Scanner input=new Scanner(System.in);
System.out.print("please enter price(1) ");
double price1=input.nextDouble();
System.out.print("please enter price(2) ");
double price2=input.nextDouble();
double discounted1=(1/3)*price1;
double discounted2=(1/3)*price2;
int eq1=(int)(discounted1*1508);
int eq2=(int)(discounted2*1508);
int w1;
int w2;
int w3;
String f=discounted1+"";
String d=discounted2+"";
String i=price1+"";
String s=price2+"";
String a=eq1+"";
String b=eq2+"";
if(price1>price2){
w1=i.length();
w2=f.length();
w3=a.length();
}
else{
w1=s.length();
w2=d.length();
w3=b.length();
}
System.out.println("Price(in USD) \tDiscounted\tEquivalent Price (in LL)");
System.out.printf("$%w1f\t$%w2f\tLL%w3d\n", price1,discounted1,eq1);
System.out.printf("$%w1f\t$%w2f\tLL%w3d\n", price2,discounted2,eq2);
}
}
它给我的错误是线程中的异常" main":
java.util.UnknownFormatConversionException: Conversion = 'w'
at java.util.Formatter$FormatSpecifier.conversion(Unknown Source)
at java.util.Formatter$FormatSpecifier.<init>(Unknown Source)
at java.util.Formatter.parse(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.io.PrintStream.format(Unknown Source)
at java.io.PrintStream.printf(Unknown Source)
at Discount.main(Discount.java:40)