/
Main.java
45 lines (33 loc) · 876 Bytes
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.util.Scanner;
/* 你的代码将被嵌入到这里 */
class Rectangle {
private double height, width;
Rectangle() {
this.height = 1;
this.width = 1;
}
Rectangle(double height, double width) {
this.height = height;
this.width = width;
}
double getArea() {
return this.height * this.width;
}
double getPerimeter() {
return 2 * (this.height + this.width);
}
}
/**
* @author Fancyking
*/
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double w = input.nextDouble();
double h = input.nextDouble();
Rectangle myRectangle = new Rectangle(w, h);
System.out.println(myRectangle.getArea());
System.out.println(myRectangle.getPerimeter());
input.close();
}
}