System.out.println("请输入三角形的三条边:");
Scanner input = new Scanner(System.in);
int a = input.nextInt();
int b = input.nextInt();
int c = input.nextInt();
TreeSet arr = new TreeSet();
arr.add(a);arr.add(b);arr.add(c);
Integer max,mid,min=0;
Iterator it = arr.iterator();
min=(Integer)it.next();
mid=(Integer)it.next();
max=(Integer)it.next();
System.out.println("Can edges 1,2,and 1 form a triagle?"+((min+mid>max)?"true":"false"));
class A {
public static boolean isTriangle(int a, int b, int c) {
// 三边必须都大于0
if (a <= 0 || b <= 0 || c <= 0)
return false;
// 判断是否成三角的依据
if (a + b <= c || a + c <= b || b + c <= a)
return false;
return true;
}
public static void main(String[] args) {
int a = 2, b = 2, c = 5;
System.out.printf("Can edges %d,%d, and %d form a triagle?"
+ isTriangle(a, b, c), a, b, c);
}
}
public static void main(String[] args) {
//必须是两边只和大于第三边才对!
//我现在做三个固定的数。你可以用键盘输入Scanner
int a=4;
int b=5;
int b=6;
if((a+b>c)&&(a+c>b)&&(b+c>a)){ System.out.println("Can edges "+a+","+b+"and 1 form a triagle?true");}
else {System.out.println("Can edges "+a+","+b+"and 1 form a triagle?false");}
}
占坑先~~代码稍后送上
import java.util.*;
public class P{
public static void main(String args[]){
double a,b,c;
Scanner reader=new Scanner(System.in);
a=reader.nextDouble();
b=reader.nextDouble();
c=reader.nextDouble();
if(aSystem.out.printf("Can edges %f,%f,and %f form a triagle?ture ",a,b,c);
else
System.out.printf("Can edges %f,%f,and %f form a triagle?false",a,b,c);
}
}
public static boolean isEdges(int a, int b, int c) {
int d = 0;
if (b > a) {
d = b;
b = a;
a = d;
}
if (c > a) {
d = c;
c = a;
a = d;
}
if ((b + c) > a) {
return true;
} else {
return false;
}
}
public static void main(String[] args) {
int a = 2;
int b = 2;
int c = 5;
boolean boo = Test.isEdges(a, b, c);
System.out.println("Can edges "+a+","+b+" and ,"+c+" form a triagle?"+boo);
}
}