Java定义一个三角形类,将求面积,周长,内切圆,外接圆等方法放入类中,并验证
问题描述:
Java定义一个三角形类,将求面积,周长,内切圆,外接圆等方法放入类中,并验证
答
public class Triangle {
int edge1;
int edge2;
int edge3;
Triangle(int a,int b,int c){
edge1 = a;
edge2 = b;
edge3 = c;
double s = (edge1+edge2+edge3)/2;
if(s0) {
max = triangle.edge2;
}else {
max = triangle.edge3;
}
r = (perimeter(triangle)-(2*max))/2;
return r;
}
/**
* 外接圆半径
*/
public double circumcircle(Triangle triangle){
int max;
double r;
if (triangle.edge1-triangle.edge2>0) {
if (triangle.edge1-triangle.edge3>0) {
max = triangle.edge1;
}else {
max = triangle.edge3;
}
}else if(triangle.edge2-triangle.edge3>0) {
max = triangle.edge2;
}else {
max = triangle.edge3;
}
r = max/2;
return r;
}
内切圆,外接圆你要得到什么?圆心?半径?
半径都给你求了;
圆心得放在坐标系里~