创建一个三角形类,成员变量三边,方法求周长,创建类主类A来测试它。
public class zhouchang { private double a; private double b; private double c; public double getA() { return a; } public void setA(double a) { this.a = a; } public double getB() { return b; } public void setB(double b) { this.b = b; } public double getC() { return c; } public void setC(double c) { this.c = c; } public double getZhouchang() { return a+b+c; } }
public class Test07 { public static void main(String[] args) { zhouchang sjx=new zhouchang(); sjx.setA(11); sjx.setB(12); sjx.setC(13); System.out.println("三边a=11,b=12,c=13的周长是:"+sjx.getZhouchang()); } }