# java三角形图形计算器怎么判断边？-问答-阿里云开发者社区-阿里云

## java三角形图形计算器怎么判断边？

``````public class SanJiaoXing {
float length;
float high;
/**
* @param args
*/
float zhouChang(){
float zhou = 3*length;
return zhou;
}
float mianJi(){
float mian = (length*high)/2;
return mian;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
SanJiaoXing san = new SanJiaoXing();
san.length = 6;
san.high = 5;
System.out.println("请输入三角形的长和高：");
Scanner sc = new Scanner(System.in);
san.length = sc.nextFloat();
san.high = sc.nextFloat();//从键盘导入

float zc = san.zhouChang();//通过对象调用周长计算面积
System.out.println("周长"+zc);
float mj = san.mianJi();
System.out.println("面积"+mj);
}
}``````
Java

• 蛮大人123
2019-07-17 19:32:29
``````public class Test
{
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
System.out.println("请输入三角形边长：");
double a=scan.nextDouble();
double b=scan.nextDouble();
double c=scan.nextDouble();
Triangle s=new Triangle();
if((a+b)>c&&(a+c)>b&&(b+c)>a){
s=new Triangle(a,b,c);
System.out.println("三角形的三边分别为："+a+"\t"+b+"\t"+c);
}
else{
System.out.println("输入的三边不能形成三角形！");
System.exit(0);
}
System.out.println("周长为："+s.round());
System.out.println("面积为："+s.area());
}
}
class Triangle{
double a;
double b;
double c;
public Triangle(){
}
public Triangle(double x,double y,double z){
this.a=x;
this.b=y;
this.c=z;
}
public double round(){
return a+b+c;
}
public double area(){
double p=(this.a+this.b+this.c)/2.0;
double x=Math.sqrt(p*(p-this.a)*(p-this.b)*(p-this.c));
return x;
}
}``````
0 0
+ 订阅