import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()){ int[] a= new int[3]; for (int i = 0; i < 3; i++) a[i]= scanner.nextInt(); Arrays.sort(a); int x = a[0]*a[0]+a[1]*a[1]; int y = a[2]*a[2]; if (x<y) System.out.println("钝角三角形"); else if (x==y) System.out.println("直角三角形"); else System.out.println("锐角三角形"); } } }
本题不算复杂,原理有人说了。
像这种判定:等腰直角、直角、等边、等腰、普通三角形、构不成三角形的会更加复杂。
import java.util.Arrays;
import java.util.Scanner;
/**
* @author Allen_Hua
* @create_time 创建时间:May 13, 2018 3:40:48 PM 类说明
*/
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while (scan.hasNext()) {
int[] data = new int[3];
for (int i = 0; i < data.length; i++) {
data[i] = scan.nextInt();
}
Arrays.sort(data);
int judge = data[0] * data[0] + data[1] * data[1] - data[2] * data[2];
if (judge > 0) {
System.out.println("锐角三角形");
} else if (judge == 0) {
System.out.println("直角三角形");
} else {
System.out.println("钝角三角形");
}
}
}
}