import java.util.Scanner;
class Rect {
private int length;
private int width;
public Rect(int length) {
this(length, length);
}
public Rect(int length, int width) {
if (length < 0) {
length = 0;
}
if (width < 0) {
width = 0;
}
this.length = length;
this.width = width;
}
/*public int getlength() {
return length;
}
public void setlength(int length) {
if (length < 0) {
length = 0;
}
this.length = length;
}
public int getwidth() {
return width;
}
public void setwidth(int width) {
if (width < 0) {
width = 0;
}
this.width = width;
}*/
public int length() {
return 2 * (length + width);
}
public int area() {
return length * width;
}
public String toString() {
String result = length + " " + width + " " + length() + " " + area();
return result;
}
}
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner cin = new Scanner(System.in);
while (cin.hasNext()) {
Rect rect;
String str = cin.nextLine();
String[] arr = str.split(" ");
int count = arr.length;
if (count == 1) {
int length = Integer.parseInt(arr[0]);
rect = new Rect(length);
} else {
int length=Integer.parseInt(arr[0]);
int width=Integer.parseInt(arr[1]);
rect = new Rect(length,width);
}
System.out.println(rect.toString());
}
cin.close();
}
}
长方形的周长面积
最新推荐文章于 2023-12-23 17:59:33 发布