开发者社区> 问答> 正文

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);
}
}

展开
收起
蛮大人123 2016-06-08 18:02:23 2354 0
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪
    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;
        }
    }
    2019-07-17 19:32:29
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载