if语句中的数学问题

时间:2014-10-17 23:37:25

标签: java if-statement compilation

代码:

import java.util.Scanner; 
public class testqu {

        public static void main(String[] args) { 
          Scanner console = new Scanner(System.in); 
          System.out.println("Enter the length of the first side of the triangle"); 
          double a = console.nextInt(); 
          System.out.println("Enter the length of the second side of the triangle"); 
          double b = console.nextInt(); 
          System.out.println("Enter the length of the third side of the triangle"); 
          double c = console.nextInt(); 


          if ((a*a) + (b*b) = (c*c))
            System.out.println("The triangle is a right triangle!");



} 
}

作业:

在直角三角形中,最长边的长度的平方等于另外两边长度的平方和。编写一个程序,提示用户输入三角形三边的长度,然后输出一条消息,指示三角形是否为直角三角形。无论输入3边长度的顺序如何,程序都能正常工作。

我的问题:代码无法编译,找到:变量,必需:值

另外:我不知道怎么做,所以程序会知道三角形是否正确,即使两侧没有按顺序给出。请帮忙,我是初学者,在这项任务中遇到很多麻烦。

2 个答案:

答案 0 :(得分:3)

使用比较运算符==来比较值,而不是赋值运算符=,它不能将值赋值给变量。变化

if ((a*a) + (b*b) = (c*c))

if ((a*a) + (b*b) == (c*c))

答案 1 :(得分:1)

if ((a*a) + (b*b) = (c*c))

应该是

if ((a*a) + (b*b) == (c*c))

因为一个等号是赋值,所以需要两个才能进行比较。