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);
}
}
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;
}
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。