Java - ')' 预期错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19752135/
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
Java - ' ) ' expected error
提问by Ricardo Almeida
Bellow is part of a code I'm making that calculates volumes. I'm getting the "' ) ' expected error" 2 times. First on -> if (solidom.equalsIgnoreCase("esfera"){
, and the second one at -> if (solidom.equalsIgnoreCase("cilindro") {
. Can someone help me? :/
Bellow 是我正在制作的计算体积的代码的一部分。我收到 2 次 "')' 预期错误"。第一个在 -> if (solidom.equalsIgnoreCase("esfera"){
,第二个在 -> if (solidom.equalsIgnoreCase("cilindro") {
。有人能帮我吗?:/
private static double volume(String solidom, double alturam, double areaBasem, double raiom) {
double vol;
if (solidom.equalsIgnoreCase("esfera"){
vol=(4.0/3)*Math.pi*Math.pow(raiom,3);
}
else {
if (solidom.equalsIgnoreCase("cilindro") {
vol=Math.pi*Math.pow(raiom,2)*alturam;
}
else {
vol=(1.0/3)*Math.pi*Math.pow(raiom,2)*alturam;
}
}
return vol;
}
采纳答案by anubhava
if (solidom.equalsIgnoreCase("esfera")
should be:
应该:
if (solidom.equalsIgnoreCase("esfera"))
You have right closing parenthesis missing in your if conditions
.
您的if conditions
.
PS:You should really be using an IDE like Eclipse to write your code which will help you immensely to overcome these simple syntax errors.
PS:你真的应该使用像 Eclipse 这样的 IDE 来编写你的代码,这将极大地帮助你克服这些简单的语法错误。
回答by BackSlash
if (solidom.equalsIgnoreCase("esfera"){
You missed parenthesis:
你错过了括号:
if (solidom.equalsIgnoreCase("esfera")){
Same for
同为
if (solidom.equalsIgnoreCase("cilindro") {
It should be
它应该是
if (solidom.equalsIgnoreCase("cilindro")) {
回答by Abstraction is everything.
you are missing the closed parenthesis at the end of the condition of the if statement on both of these lines.
您在这两行的 if 语句的条件末尾都缺少右括号。