gpt4 book ai didi

java - 简单的Java困惑

转载 作者:行者123 更新时间:2023-12-01 06:32:32 25 4
gpt4 key购买 nike

我正在学习 Java 计算类(class),我对导致错误的原因感到困惑。我试图研究它,但我似乎很难搜索这种错误。

ERROR: source_file.java:12: error: cannot find symbol
double r = scan.nextDouble; ^
symbol: variable nextDouble
location: variable scan of type Scanner

代码:

 import java.io.*;
import static java.lang.System.*;
import java.util.Scanner;

class Rextester{


public static void main (String str[]) throws IOException {

Scanner scan = new Scanner(System.in);
System.out.println("Radius:");
double r = scan.nextDouble;
double circumference = (2 * 3.14 * r);
double area = (r * r * 3.14);
System.out.println("Circumference: " + circumference );
System.out.println("Area :" + area );

}

}

最佳答案

方法需要括号

double r = scan.nextDouble();
^

关于java - 简单的Java困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19115891/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com