One

来源:互联网 发布:中铁二院 知乎 编辑:程序博客网 时间:2024/04/28 23:13
public class TestTriAngle {

public static void main(String[] args) {
TriAngle t = new TriAngle();
t.setBase(5);
t.setHigh(8);
t.info();
}


}
class TriAngle{
private int base;
private int high;

public int getBase() {
return base;
}
public void setBase(int base) {
this.base = base;
}
public int getHigh() {
return high;
}
public void setHigh(int high) {
this.high = high;
}
public void info(){
if( base < 0 || high < 0 ){
System.out.println("输入有误!");
}else{
System.out.println("三角形面积为:"+(base*high)/2);
}
}


}
原创粉丝点击