public class Triangle {
int x,y,z; //這是三角形三條邊的長度
private void triangle(int x,int y,int z) {
this.x=x;
this.y=y;
this.z=z;
}
private int perimeter(){
return this.x+this.y+this.z;
private double area(){
int p = this.perimeter() / 2;
return Math.sqrt(p*(p-this.x)*(p-this.y)*(p-this.z));
public static void main(String[] args) throws Exception {
Triangle t = new Triangle(3,4,5);
System.out.println("該三角形的周長為:" + t.perimeter());
System.out.println("該三角形的面積為:" + t.area());
上面程式碼儲存為Triangle.java即可測試執行~~手寫程式碼,不保證完全正確,但思路絕對是正確的
public class Triangle {
int x,y,z; //這是三角形三條邊的長度
private void triangle(int x,int y,int z) {
this.x=x;
this.y=y;
this.z=z;
}
private int perimeter(){
return this.x+this.y+this.z;
}
private double area(){
int p = this.perimeter() / 2;
return Math.sqrt(p*(p-this.x)*(p-this.y)*(p-this.z));
}
public static void main(String[] args) throws Exception {
Triangle t = new Triangle(3,4,5);
System.out.println("該三角形的周長為:" + t.perimeter());
System.out.println("該三角形的面積為:" + t.area());
}
}
上面程式碼儲存為Triangle.java即可測試執行~~手寫程式碼,不保證完全正確,但思路絕對是正確的