日期:2014-05-18 浏览次数:20654 次
import java.util.Scanner;
class Square {
double x, y;
Square(double x1, double y1) {
x = x1;
y = y1; // 构造方法
}
double getArea() { // 求面积的方法
double s = x * y;
return s;
}
double girth() {
double length = 2 * x + (2 * y);
return length;
}
}
public class Ex2 {
public static void main(String[] args) {
System.out.println("请输入第1个参数");
Scanner s = new Scanner(System.in);
double a = Double.parseDouble(s.next());
System.out.println("请输入第2个参数");
double b = Double.parseDouble(s.next());
double s1, length1;
Square q1 = new Square(a, b);
s1 = q1.getArea();
length1 = q1.girth();
System.out.println("矩形的面积" + s1 + "矩形的周长" + length1);
}
}