打印矩形

This commit is contained in:
seahi 2024-09-08 21:14:05 +08:00
parent 3ce1276067
commit b495294af3

18
src/Example19.java Normal file
View File

@ -0,0 +1,18 @@
public class Example19 {
public static void main(String[] args) {
printRectangle(3, 40);
}
// 下面定义了一个打印矩形的方法接收两个参数其中height为高width为宽
public static void printRectangle(int height, int width) {
// 下面是使用嵌套for循环实现*打印矩形
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
System.out.print("*");
}
// System.out.print("\n");
System.out.println();
}
}
}