展开全部
代码如下,Rectangle类在java.lang包下有同名类,如需引包请注意,32313133353236313431303231363533e59b9ee7ad9431333433636166望采纳。
补充:
Rectangle类package com.baidu.question183173554138589044;
public class Rectangle {
private double width;
private double height;
public void setRectangle(int w, int h){
if(w>0 && h>0){
width = w;
height = h;
}else{
System.out.println("错误:长宽需要大于0");
}
}
public double getArea() {
return width*height;
}
}
运行主类package com.baidu.question183173554138589044;
public class Main {
public static void main(String[] args) {
Rectangle rect = new Rectangle();
rect.setRectangle(5,6);
System.out.println(rect.getArea());
}
}