[java]代码库
public class demo1
{
private float length;
private float width;
public demo1(float l,float w)
{
length=l;
width=w;
}
public void SetLength(float l)
{
if(length>0)
length=l;
else
System.out.print("ERROR");
}
public float GetLength()
{
return length;
}
public float GetWidth()
{
return width;
}
float area ()
{
return length*width;
}
float zhouchang ()
{
return 2*(length+width);
}
}
package zuoye2;
public class demo2
{
public static void main(String[] args) {
demo1 rect = new demo1(10f, 20f);
System.out.println("长方形的长:" + rect.GetLength());
System.out.println("长方形的宽:" + rect.GetWidth());
System.out.println("长方形的面积:" + rect.area());
System.out.println("长方形的周长:" + rect.zhouchang());
}
}
中级程序员
by: 云代码会员 发表于:2019-07-30 14:14:02 顶(0) | 踩(0) 回复
111
回复评论