java期末考试例题,请高手帮帮忙写下代码!谢谢了!

发布网友

我来回答

4个回答

热心网友

public class Jxcomputer{

public static void main(String [] args){

Js js = new Js(10,9,2);

System.out.println("面积:"+js.area());
System.out.println("周长:"+js.sjlength());
System.out.println("面积(带参):"+js.area(js.getA(), js.getB(), js.getC()));
System.out.println("周长(带参):"+js.sjlength(js.getA(), js.getB(), js.getC()));
}

}

class Js {

private int a;

private int b;

private int c;

public Js(int a, int b , int c){

this.a = a;

this.b = b;

this.c = c;

}

//无参的
int area(){
return (this.a + this.b + this.c)/2;
}

int sjlength(){
return (this.a + this.b + this.c);
}
//有参的
int area(int a, int b , int c){
return (a + b + c)/2;
}

int sjlength(int a, int b , int c){
return (a + b + c);
}

public int getA() {
return a;
}

public void setA(int a) {
this.a = a;
}

public int getB() {
return b;
}

public void setB(int b) {
this.b = b;
}

public int getC() {
return c;
}

public void setC(int c) {
this.c = c;
}

}

热心网友

// sj.java
public class sj {
private double a;
private double b;
private double c;
public sj(double a,double b,double c){
this.a = a;
this.b = b;
this.c = c;
}
public double getA() {
return a;
}
public double getB() {
return b;
}
public double getC() {
return c;
}
public double area(){
// return Math.sqrt(Math.abs(2*a*a*b*b+2*a*a*c*c+2*b*b*c*c-a*a*a*a-b*b*b*b-c*c*c*c)) / 4;
return (a + b + c) / 2
}
public double sjlength(){
return a + b + c;
}
}

// jxcomputer.java
public class jxcomputer {
public static void main(String[] args) {
sj sjObj = new sj(3, 6, 8);
double area = sjObj.area();
double leangth = sjObj.sjlength();
System.out.println(area);
System.out.println(leangth);
}
}

热心网友

三角形面积公式: 其中s=(a+b+c)/2

你的这个公式好像有问题哦。。。

是想写海*式的吧?

热心网友

楼上有没有考虑输入的三个数之后.这个三角形成立吗?
a+b>c && a-b<c

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com