public class TestMyRectangle{
public static void main(String args[]){
MyRectangle obj=new MyRectangle(100,100,300,200);
System.out.println(obj.tostring());
}
}
class MyRectangle{
private int xUp,yUp,xDown,yDown,W,H,A;
MyRectangle(){}
MyRectangle(int xUp,int yUp,int xDown,int yDown){
this.xUp=xUp;
this.yUp=yUp;
this.xDown=xDown;
this.yDown=yDown;
}
void getW(int xDown,int xUp){
W=xDown-xUp;
}
void getH(int yDown,int yUp){
H=yDown-yUp;
}
void area(){
A=W*H;
}
String tostring(){
return "矩形的宽:"+W+"高:"+H+"面积:"+W*H;
}
}
为什么输出总是0啊?请教各位java高手
那应该怎么写啊?请教