用java编译一个计算长方形的周长与面积
来源:百度知道 编辑:UC知道 时间:2024/05/23 19:35:21
import java.io.*;
class CBox
{
int width;
int height;
int perimeter(int width,int height)
{
return 2*(width+height);
}
int area(int width,int height )
{
return width*height;
}
}
public class chang
{
public static void main(String args[])throws IOException
{
int a,b;
String str;
BufferedReader buf1,buf2;
buf1=new BufferedReader(new InputStreamReader(System.in));
buf2=new BufferedReader(new InputStreamReader(System.in));
System.out.print("请输入2个数的值:");
str=buf1.readLine();
a=Integer.parseInt(str);
str=buf2.readLine();
b=Integer.parseInt(str);
System.out.println(a+" "+b);
CBox rect1=new CBox();
System.out.println("周长为:"+rect1.perimeter(a,b));
System.out.println("面积为:"+rect1.area(a,b));
}
}
我觉得把