Java编程 求矩形周长和面积

来源:百度知道 编辑:UC知道 时间:2024/05/22 02:41:29
请写上类或变量
分析或者流程图
谢谢

import java.util.*;
public class Rectangle {

private float length; //定义长变量
private float width; // 宽变量
public Rectangle(float length,float width){
this.length=length;
this.width=width;
}
public float getGirth(){
return (length+width)*2;

} //求周长方法

public float getArea(){
return length*width;
} //求面积方法
public static void main (String[] args) {
Scanner in=new Scanner(System.in);//调用输入方法

System.out.println ("请输入矩形的长:");
float a=in.nextFloat();
System.out.println ("请输入矩形的宽:");
float b=in.nextFloat();
System.out.println ("矩形周长为:"+new Rectangle(a,b).getGirth());
System.out.println ("矩形面积为:"+new Rectangle(a,b).getArea());

}

}
//Jcreator4.0编译通过,写的比较简单 只有简单的功能 刚刚写的求周长时忘乘2了...

public class Rectangle
{
private float sid