Java 新手并不断出现语法错误

我是编码新手,我不断收到关于标记“.”的语法错误,; 在第 21、22 和 23 行(System.out.println)。我可以弄清楚我们正是错误是?


// calculator for the price of milk

import 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();

   }

}


森栏
浏览 153回答 3
3回答

繁花不似锦

语句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值。

鸿蒙传说

您需要先了解 Java 语言的语法和基础知识。从您的代码来看,您似乎是 Java 语言的新手。您可以在代码中进行以下更正:System.out.println( "Milk cartons needed ="+ cartonsneeded);            System.out.println("Cost of production ="+ produced * productioncost);         System.out.println("Profit = "+produced * cartonprofit);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java