package pcj.com;
class Tangle {
int a, b, c;
Tangle(int a, int b, int c) {
this.a=a;
this.b=b;
this.c=c;
}
public double triangleArea(){
float p=(a+b+c)/2f;
float s1=(float)Math.sqrt(p*(p-a)*(p-b)*(p-c));
return s1;
}
public int triangleGrith() {
return a + b + c;
}
void display(){
System.out.println("三角形面积:"+this.triangleArea());
}
void display_01(){
System.out.println("三角形周长:"+this.triangleGrith());
}
}
class Ladder{
int d1,d2,h;
Ladder(int d1,int d2,int h){
this.d1=d1;
this.d2=d2;
this.h=h;
}
public double LadderArea(){
float s2=((d1+d2)*h)/2f;
return s2;
}
void display_02(){
System.out.println("梯形的面积是:"+this.LadderArea());
}
}
class Circle{
int r;
Circle(int r){
this.r=r;
}
public double circleArea(){
float s3=(float) 3.14*r*r;
return s3;
}
public double circleGirth(){
double c=(double) 2*3.14*r;
return c;
}
void display_03(){
System.out.println("圆形的面积是:"+this.circleArea());
}
void display_04(){
System.out.println("圆形的周长是:"+this.circleGirth());
}
}
public class Graph {
public static void main (String[] args){
Tangle t1=new Tangle(3,4,5);
t1.display();
t1.display_01();
Ladder l1=new Ladder(3,5,6);
l1.display_02();
Circle c1=new Circle(4);
c1.display_03();
c1.display_04();
}
}
Java面向对象编程求三角形面积,周长;梯形面积;圆形周长面积
最新推荐文章于 2024-07-29 14:22:26 发布