代码:
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条边的长度输入顺序如何,程序都能正确运行。
我的问题:代码无法编译,发现:变量,必需:值
另外:我不知道如何制作它,这样程序就会知道三角形是否正确,即使边没有按顺序给出。请帮忙,我是一个初学者,在这项作业上遇到很多麻烦。
最佳答案
使用比较运算符==
来比较值,而不是赋值运算符=
,后者不能将值赋给值,只能赋给变量。改变
if ((a*a) + (b*b) = (c*c))
至
if ((a*a) + (b*b) == (c*c))
关于java - if 语句中的数学问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26434826/