当前位置: 首页 > 知识库问答 >
问题:

Java:运算符-是未定义的参数类型双,双[]

岳凯康
2023-03-14

下面的方法中不断出现错误“The operator-is undefined for The argument type double[],double”,我不知道为什么或如何修复它。

   public static double inputstartX (double targetX[])throws IOException{
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("Please enter the horizontal starting point");
            while (true){
                try {
                    double x = Double.parseDouble(br.readLine());
                    if ((targetX-x)<=500 && (targetX-x)>=50){
                        return x;
                    }
                    else {
                        System.out.println("The starting point must be at a horizontal distance between 50 to 500 meters away from the target");
                        System.out.println("Please enter the horizontal starting point again");
                    }
                }
                catch (NumberFormatException e){
                    System.out.println("Invalid Input, please try again");
                }
            }

特别是在以下行:“如果((targetX-x)

共有2个答案

居英资
2023-03-14

TaretX是一个双精度数组。这意味着您不能从它中细分另一个双精度。您首先必须指定数组中的一个元素。

示例:

targetX[0] -= x;
        ^
  index of element (in this case: 0)
濮翰学
2023-03-14

您正在尝试从数组中减去,它不是双精度。
数组本身存储多个相同类型的值。
您需要调用其中一个,例如Target etX[0],它将给出第一个值。

或者,如果您认为[]是错误,只需将其删除。

 类似资料:
  • 我的Java代码没有什么问题。我正在使用下面的代码,但Eclipse总是提示相同的消息“参数类型Test1,int的运算符未定义”。但是如果我将代码更改为“System.out.println(test1”“100);”或“System.out.println”(“100 test1”)或“System.out.println(100”“test1);”,没有问题。 有人对此有想法吗?请帮忙。多谢

  • 在我的代码中,我一直得到这样的错误:操作符!=对于参数类型boolean和int是未定义的,我不知道该怎么做来修复它。该错误出现在eclipse内部以及启动时 如有帮助,我们将不胜感激:)谢谢!

  • 问题内容: 我得到这个错误 问题答案: 具有无效的返回类型。更改方法的返回类型以返回值

  • 我这里有这个代码: 但我得到了错误信息: 接线员 为什么呢?如何修复代码? 以下是代码的文本形式:

  • 问题内容: 我只是试图制作一个简单的类,让我弄清楚文件的长度: 我遇到了一个问题 我得到错误: 未为参数类型定义运算符!= int,null 有什么想法为什么会阻止这种情况吗? 问题答案: Java中的原始类型不能为。如果要检查0,请执行。

  • 是否有任何方法可以使用Retrofit并将参数运算符符号替换为我自己的运算符(例如)。 这将创建 但我需要 谢啦