public class Rectangle {
private Integer length;
private Integer width;
public void setDemo(Integer length, Integer width){
if(length < 0){
throw new RuntimeException("length 不能小于0");
}
if(width < 0){
throw new RuntimeException("width 不能小于0");
}
this.length = length;
this.width = width;
}
public Integer arer(){
return length * width;
}
}
public class Test {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入length:");
int length = scanner.nextInt();
System.out.println("请输入width:");
int width = scanner.nextInt();
Rectangle rectangle = new Rectangle();
rectangle.setDemo(length,width);
System.out.println(rectangle.arer());
}
}