public class Rectangle {
public double length;
public double width;
public Rectangle(double length, double width) {
super();
this.length = length;
this.width = width;
}
public void perimeter(){
System.out.println("周长为:"+(length+width)*2);
}
public void area(){
System.out.println("面积为:"+length*width);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
System.out.println("请输入矩形的长度");
double length=sc.nextDouble();
System.out.println("请输入矩形的宽度");
double width=sc.nextDouble();
Rectangle re=new Rectangle(length, width);
re.perimeter();
re.area();
}
}
public double length;
public double width;
public Rectangle(double length, double width) {
super();
this.length = length;
this.width = width;
}
public void perimeter(){
System.out.println("周长为:"+(length+width)*2);
}
public void area(){
System.out.println("面积为:"+length*width);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
System.out.println("请输入矩形的长度");
double length=sc.nextDouble();
System.out.println("请输入矩形的宽度");
double width=sc.nextDouble();
Rectangle re=new Rectangle(length, width);
re.perimeter();
re.area();
}
}