Java 标记“”上的语法错误;eqn";删除此令牌

Java 标记“”上的语法错误;eqn";删除此令牌,java,arrays,syntax,double,token,Java,Arrays,Syntax,Double,Token,我对Java相当陌生,正在学习一门课程,但我无法理解我不断遇到的这个小语法错误。我一直在研究这个问题,盯着它看了一段时间,但就是想不出来。我不是要求某人完成这个项目,只是需要帮助这个错误。对不起,如果我没有在正确的部分发布。下面是代码 import java.util.*; public class SolveEqu { public static void main(String[] args) { Scanner sc=new Scanner(System.in);

我对Java相当陌生,正在学习一门课程,但我无法理解我不断遇到的这个小语法错误。我一直在研究这个问题,盯着它看了一段时间,但就是想不出来。我不是要求某人完成这个项目,只是需要帮助这个错误。对不起,如果我没有在正确的部分发布。下面是代码

import java.util.*;
public class SolveEqu {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        double arr[]=new double[3];  //passing array as parameter
        System.out.println("Enter the three coefficients of the equation separated by spaces");

        for(int i=0;i<3;i++)
            arr[i]=sc.nextDouble();     

        double result[]=solveQuadratic(arr); // unknown   

        //if result is negative
        if(result.length==1) {                 
            System.out.println("The equation has no real roots");
        }
             
        //if result is = to zero
        else if(result.length==2) {      
            System.out.println(" The equation has just one real root");
            System.out.format("The root is %.2f",result[1]);
        }
             
        //if result is positive
        else                               
        {
            System.out.println("The equation has two real roots");
            System.out.format("The root are %.2f and %.2f",result[1],result[2]);    
         }
    }

    public static double[] solveQuadratic(double[] eqn) {  // method heading from assignment

        double discriminant=eqn[1]eqn[1]-(4eqn[0]eqn[2]);  // discriminant of the quadratic equation
        if(discriminant>0) {                  //   discriminant is positive and has 2 real roots       
            double r1=(-eqn[1]+Math.sqrt(discriminant))/(2eqn[0]);   // equation for square roots
            double r2=(-eqn[1]-Math.sqrt(discriminant))/(2eqn[0]);  //equation for square roots
            double res[]= {2,r1,r2};      
            return res;
        }
        else if(discriminant==0)  //equal to zero the equation has just one real root          
        {
            double r1=(-eqn[1])/(2eqn[0]);  
            double res[]= {1,r1};             
            return res;
        }
        else     //   the equation has no real roots 
        {
            double res[]= {0};    //unknown  
            return res;    //unknown 
        }
    }
}
它显示“无效浮点文字数”和“eqn上出现语法错误,删除此标记”


有人能解释一下这个错误是什么意思吗?

@f1sh的评论是同一问题的多个例子中的第一个

如前所述,对于
eqn[1]*eqn[1]
,您需要一个乘法运算符

对于
4eqn[0]eqn[2]
,同样适用。如果我记得我的二次曲线,你试图在那里乘法,所以你需要
4*eqn[0]*eqn[2]
。该行应为:

double discriminant=eqn[1]*eqn[1]-(4*eqn[0]*eqn[2]);
同样,在计算
r1
r2
时,
2eqn[0]
应该是
2*eqn[0]
。在您计算的两个位置
r1
都需要该修复


因此,基本规则是,在java中,必须指定两个符号之间的运算符。与数学不同的是,相邻书写并不意味着乘法。

你希望那一行做什么?!是否缺少数学运算符?
eqn[1]eqn[1]
不是有效的语句。如果你想让这些值相乘,你需要使用
eqn[1]*eqn[1]
Ahh,谢谢-我忽略了你需要这两者之间的语法。我现在只能在-(4eqn[0]上看到一个错误,这不是一个有效的语句,也有点困惑,这是同一个问题。你期望什么
4eqn[0]
to be?基本上,我们是在求一个二次方程的平方根,对于我们正在研究并遇到困难的特定部分,是转换b2(平方)-4ac。这有意义吗?很难解释
double discriminant=eqn[1]*eqn[1]-(4*eqn[0]*eqn[2]);