编译时出现意外类型

时间:2015-11-04 18:39:42

标签: java types compilation int

我在JAVA中编写了以下代码:

import java.util.Scanner;

public class Equations
    {
        public static void main (String [] args)
        {
            Scanner scan = new Scanner (System.in);
            System.out.println ("This program solves a system of 2 linear  equations" +"\n"+
        "Enter the coefficients a11 a12 a21 a22 b1 b2:");

            int a11 = scan.nextInt();
            int a12 = scan.nextInt();
            int a21 = scan.nextInt();
            int a22 = scan.nextInt();
            int b1 = scan.nextInt();
            int b2 = scan.nextInt();

            System.out.println ("Eq: " + a11 + "*x1" + "+" + a12 + "*x2 = " + b1);
            System.out.println ("Eq: " + a21 + "*x1" + "+" + a22 + "*x2 = " + b2);

            if(((a11*a22)-(a12*a21)) != 0){
                double Equ1single = ((b1*a22)-(b2*a12))/((a11*a22)-(a12*a21));
                double Equ2single = ((b2*a11)-(b1*a21))/((a11*a22)-(a12*a21));
                System.out.println ("Single solution: (" + Equ1single + "," + Equ2single + ")");
            } 

            if(((b2*a11)-(b1*a21)) = 0){
                System.out.println ("Many solutions");
            }

       }
}

我在BlueJay环境中编译此代码时遇到错误。 错误如下:

  

意外类型。必需变量;找到值。

它标志着&#34 ;-(b1 * a21)"作为问题。但我确实将a21声明为int。而且," if"之前的条件是"相同的"并且不会给出任何错误。

编译这个有什么问题?

1 个答案:

答案 0 :(得分:-1)

if(((b2*a11)-(b1*a21)) = 0){

应该是

if(((b2*a11)-(b1*a21)) == 0){