标签:
1 //创建一个三角形类,成员变量三边,方法求周长,创建类主类A来测试它。 2 private int bian1; 3 private int bian2; 4 private int bian3; 5 private int C; 6 7 8 public int getC() { 9 return C; 10 } 11 public int getBian1() { 12 return bian1; 13 } 14 public void setBian1(int bian1) { 15 this.bian1 = bian1; 16 } 17 public int getBian2() { 18 return bian2; 19 } 20 public void setBian2(int bian2) { 21 this.bian2 = bian2; 22 } 23 public int getBian3() { 24 return bian3; 25 } 26 public void setBian3(int bian3) { 27 this.bian3 = bian3; 28 } 29 30 31 public sanjiaoxing(int bian1, int bian2, int bian3) { 32 super(); 33 this.bian1 = bian1; 34 this.bian2 = bian2; 35 this.bian3 = bian3; 36 37 } 38 public int qiuC() 39 { 40 if(bian1+bian2>bian3 41 &&bian1+bian3>bian2 42 &&bian2+bian3>bian1) 43 { 44 C=this.bian1+this.bian2+this.bian3; 45 System.out.println("三角形的周长为:"+C); 46 } 47 return C; 48 } 49 public static void main(String[] args) { 50 // TODO 自动生成的方法存根 51 sanjiaoxing sanjiao=new sanjiaoxing(2,3,4); 52 sanjiao.qiuC(); 53 System.out.println("三角形的周长为:"+sanjiao.qiuC()); 54 }
标签:
原文地址:http://www.cnblogs.com/yg6405816/p/5514005.html