public class changfangxing
{
int chang,kuang;
int zhouchang()
{
return 2*(chang+kuang);
}
int mianji()
{
return chang*kuang;
}
public static void main(String[] rags)
{
changfangxing cfx=new changfangxing();
cfx.chang=4;
cfx.kuang=5;
System.out.println(cfx.zhouchang());
System.out.println(cfx.
mianji());
}
}
程序不合规范啦
数据成员最好私有,方法公有。
public class Rect
{
private int height;
private int width;
public Rect(int height,int width)
{
this.height=height;
this.width=width;
}
public int Perimeter()
{
return 2*(height+width);
}
public int Area()
{
return height*width;
}
public static void main(String[] args)
{
Rect rect=new Rect(4,5);
System.out.println(rect.Perimeter());
System.out.println(rect.Area());
}
}