Java
```java
public class Rectangle {
private int width;
private int height;
public Rectangle(int width, int height) {
this.width = width;
this.height = height;
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public void printRectangle() {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
System.out.print("* ");
}
System.out.println();
}
}
public static void main(String[] args) {
Rectangle rectangle = new Rectangle(5, 3);
rectangle.printRectangle();
}
}
```
C
```c
include
int main() {
int a, b, flag, i, j;
// 高,宽,flag表示实心还是空心
char c;
scanf("%d %d %c %d", &a, &b, &c, &flag);
if (flag == 0) { // 空心
for (i = 1; i <= a; i++) {
for (j = 1; j <= b; j++) {
if (i == 1 || i == a || j == 1 || j == b) {
// 第一行、第一列和最后一行、最后一列全部打印
printf("%c", c);
} else {
printf(" ");
}
}
printf("\n"); // 注意:每一行输出后换行
}
} else { // 实心
for (i = 1; i <= a; i++) {
for (j = 1; j <= b; j++) {
printf("%c", c);
}
printf("\n"); // 每一行输出完换行
}
}
return 0;
}
```
C++
```cpp
include using namespace std; class Rectangle { public: double width; double height; Rectangle(double width, double height) { this->width = width; this->height = height; } void setWidth(double width) { this->width = width; } void setHeight(double height) { this->height = height; } double getArea() { return width * height; } double getPerimeter() { return 2 * (width + height); } void print() const { for (double i = 0; i < height; i++) { for (double j = 0; j < width; j++) { if (j == 0 || j == width - 1) { cout << "* "; } else { cout << " "; } } cout << endl; } } }; int main() { Rectangle rect(5.0, 3.0); rect.print(); return 0; } ``` HTML5 Canvas