小编Rud*_*g9d的帖子

简单的Java混乱

我正在研究Java计算课程,我对这里导致错误的原因感到难过.我试图研究它,但我似乎很难找到这种错误.

错误:source_file.java:12:错误:找不到符号
double r = scan.nextDouble; ^
符号:变量nextDouble
位置:扫描器类型的变量扫描

码:

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

    }

}
Run Code Online (Sandbox Code Playgroud)

java

0
推荐指数
1
解决办法
206
查看次数

Java"变量名称"无法解析,IF语句中的变量出错

Scanner scan = new Scanner(System.in);

System.out.println("Enter up to 5 Tests:");
int test1 = scan.nextInt();
if (test1 > -1){
  int test2 = scan.nextInt();
} else {
  if (test2 > -1){
    int test3 = scan.nextInt();
  } else {
    if (test3 > -1){
      int test4 = scan.nextInt();
    } else {
      if (test4 > -1){
        int test5 = scan.nextInt();
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我得到一个" test2无法解析为变量" 的编译错误,除了每个变量都会发生这种错误test1.我认为这是因为test2在我们输入值之前不存在.我能做些什么让Java开心?

java variables if-statement

0
推荐指数
1
解决办法
1821
查看次数

标签 统计

java ×2

if-statement ×1

variables ×1