Java 错误:')' 预期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16555530/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 23:17:39  来源:igfitidea点击:

Java Error: ')' expected

java

提问by Salma

System.out.println("Enter a department name:");

String firstDepartment = bufRead.readLine();

System.out.println("Enter number of employees:");

val1 = Double.parseDouble(bufRead.readLine());

System.out.println("Enter cost per employee:");

val2 = Double.parseDouble(bufRead.readLine());

System.out.println("Enter sales:");

val3 = Double.parseDouble(bufRead.readLine());

System.out.println("Hello, Donaldio! Your " + firstDepartment + "profit is " "$" + (val3 - val1 * val2));

String pleaseContinue = bufRead.readLine();

System.out.println("Please press enter!");

This is just one part of my code. Unfortunately, the command prompt keeps telling me there's an error at

这只是我代码的一部分。不幸的是,命令提示符一直告诉我有一个错误

System.out.println("Hello, Donaldio! Your " + firstDepartment + "profit is " "$" + (val3 - val1 * val2));

It says that there's a ')' expected. I understand what it means, but I can't find where the parentheses is missing... I'm so confused. Any help would be greatly appreciated!

它说有一个 ')' 预期。我明白这意味着什么,但我找不到括号丢失的地方......我很困惑。任何帮助将不胜感激!

回答by Neoh

You missed a +sign in between

你错过了+中间的一个标志

"profit is " "$"
            ^

Based on the logic, I think you actually don't mean to include those double quotes:

根据逻辑,我认为您实际上并不是要包含这些双引号:

"profit is $"

回答by karthikr

System.out.println("Hello, Donaldio! Your " + firstDepartment + "profit is " "$" + (val3 - val1 * val2));

should be

应该

System.out.println("Hello, Donaldio! Your " + firstDepartment + "profit is $" + (val3 - val1 * val2));