帮忙解决这道java题
答案:3 悬赏:10 手机版
解决时间 2021-02-24 05:46
- 提问者网友:凉末
- 2021-02-23 06:31
帮忙解决这道java题
最佳答案
- 五星知识达人网友:思契十里
- 2021-02-23 07:59
//定义三角形类和方法
public class Triangle {
public double a;
public double b;
public double c;
public Triangle(){
a = 0;
b = 0;
c = 0;
}
public Triangle(double a, double b, double c){
this.a = a;
this.b = b;
this.c = c;
}
public double Area(Triangle triangle){
double s = (triangle.a + triangle.b + triangle.c) / 2;
return Math.sqrt(s * (s - triangle.a) * (s - triangle.b) * (s - triangle.c));
}
}
//测试程序
public class TriangleTest {
public static void main(String[] args) {
Triangle t1 = new Triangle(2, 3, 4);
System.out.println(t1.Area(t1));
}
}
public class Triangle {
public double a;
public double b;
public double c;
public Triangle(){
a = 0;
b = 0;
c = 0;
}
public Triangle(double a, double b, double c){
this.a = a;
this.b = b;
this.c = c;
}
public double Area(Triangle triangle){
double s = (triangle.a + triangle.b + triangle.c) / 2;
return Math.sqrt(s * (s - triangle.a) * (s - triangle.b) * (s - triangle.c));
}
}
//测试程序
public class TriangleTest {
public static void main(String[] args) {
Triangle t1 = new Triangle(2, 3, 4);
System.out.println(t1.Area(t1));
}
}
全部回答
- 1楼网友:煞尾
- 2021-02-23 10:01
这个是学习java必须会做的题目,在这里帮你回答只会是在害你,看看书中的例子,自己学着创建一个类,慢慢的就熟悉了。加油吧!少年
- 2楼网友:猎心人
- 2021-02-23 08:29
public class Triangle {
double a;
double b;
double c;
public Triangle(){
a=0;
b=0;
c=0;
}
public Triangle(double a,double b, double c){
this.a=a;
this.b=b;
this.c=c;
}
public double Area(){
double area;
double s=(a+b+c)/2;
area =Math.sqrt(s*(s-a)*(s-b)*(s-c));
return area;
}
public static void main(String[] args){
Triangle triangle = new Triangle(3,4,5);
System.out.println(triangle.Area());
}
}
double a;
double b;
double c;
public Triangle(){
a=0;
b=0;
c=0;
}
public Triangle(double a,double b, double c){
this.a=a;
this.b=b;
this.c=c;
}
public double Area(){
double area;
double s=(a+b+c)/2;
area =Math.sqrt(s*(s-a)*(s-b)*(s-c));
return area;
}
public static void main(String[] args){
Triangle triangle = new Triangle(3,4,5);
System.out.println(triangle.Area());
}
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯