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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 19:55:25  来源:igfitidea点击:

Java - ' ) ' expected error

javasyntax-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 语句的条件末尾都缺少右括号。