代码:
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))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句