我是编码新手,我不断收到关于标记“.”的语法错误,; 在第 21、22 和 23 行(System.out.println)。我可以弄清楚我们正是错误是?// calculator for the price of milkimport java.util.Scanner;public class DairyCalculator{ public static void main( String [] args) { double cartonhold = 3.78; double productioncost = 0.38; double cartonprofit = 0.27; Scanner sc = new Scanner(System.in); System.out.print( "Enter how many liters of milk was produced; "); // input double produced = sc.nextInt(); double cartonsneeded = produced / cartonhold; int System.out.println( "Milk cartons needed" = cartonsneeded); double System.out.println("Cost of production" = produced * productioncost); double System.out.println("Profit" = produced * cartonprofit); sc.close(); }}
3 回答
繁花不似锦
TA贡献1851条经验 获得超4个赞
语句int double前不需要等System.out...,而且你的语句格式不正确,见下文
System.out.println("Milk cartons needed " + cartonsneeded);
System.out.println("Cost of production " + (produced * productioncost));
System.out.println("Profit " + (produced * cartonprofit));
此外,您可能想重新考虑是否要将变量保存为int或double值。
鸿蒙传说
TA贡献1865条经验 获得超7个赞
您需要先了解 Java 语言的语法和基础知识。
从您的代码来看,您似乎是 Java 语言的新手。
您可以在代码中进行以下更正:
System.out.println( "Milk cartons needed ="+ cartonsneeded);
System.out.println("Cost of production ="+ produced * productioncost);
System.out.println("Profit = "+produced * cartonprofit);
添加回答
举报
0/150
提交
取消