Java 还是新手,我的任务是为一个纸男孩制作利润计算器,但是我收到了这个错误:
Enter the number of daily papers delivered: 50
Enter the number of Sunday papers delivered: 35
The amount collected for daily papers was: Exception in thread "main" java.util
IllegalFormatConversionException: d != java.lang.Double
at java.util.Formatter$FormatSpecifier.failConversion(Unknown Source)
at java.util.Formatter$FormatSpecifier.printInteger(Unknown Source)
at java.util.Formatter$FormatSpecifier.print(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.io.PrintStream.format(Unknown Source)
at java.io.PrintStream.printf(Unknown Source)
at lab2b_MontelWhite.main(lab2b_MontelWhite.java:24)
这是我到目前为止所拥有的:
//Paper Boy's Wages Calculator
import java.util.Scanner;
public abstract class lab2b
{
public static void main(String[] args)
{
Scanner input = new Scanner( System.in);
int x;
int y;
int result;
System.out.print("Enter the number of daily papers delivered: ");
x = input.nextInt();
System.out.print("Enter the number of Sunday papers delivered: ");
y = input.nextInt();
double dailyResult = x * .3;
System.out.printf("The amount collected for daily papers was: %d\n",
dailyResult);
int SundayResult = y * 1;
System.out.printf("The amount collected for Sunday papers was: %d\n",
SundayResult);
double totalResult = dailyResult + SundayResult;
System.out.printf("The total amount of money collected was: %d\n",
totalResult);
double ProfitResult = (SundayResult + dailyResult)/2;
System.out.printf("The paper boy's profit is: %d\n", ProfitResult);
}
}
我究竟做错了什么?我添加了双打,我更改了“结果”的名称。我只是不确定我做错了什么。