package job;
/**
*/
import java.util.Scanner;
public class Space {
/*
- 面向对象编程创建一个矩形类, 求周长 面积
*/
public static void main(String[] args) {
// TODO 自动生成的方法存根
Scanner in = new Scanner(System.in);
float leng = 0.0f;
float wid = 0.0f;
Rectangle rec = new Rectangle();
System.out.println(“求矩形的周长和面积”);
System.out.print(“请输入矩形的长:”);
leng = in.nextFloat();
System.out.print(“请输入矩形的宽:”);
wid = in.nextFloat();
rec.Perimeter(leng, wid);
System.out.printf(“矩形的面积:%.2f”,rec.Area(leng, wid));
}
}
class Rectangle{
void Perimeter(float length,float width) {
float peri = 0.0f;
peri = 2*(length*width);
System.out.printf(“矩形的周长:%.2f \n”,peri);
}
float Area(float length,float width) {
return length * width;
}
}
PS:有错误的地方还请大家指正,欢迎大家在评论区留言。
注意:
网络资源海量,本人无法有效辨认是否侵权,若有侵权,请联系作者删除内容。感谢您的访问。