From b495294af3ba1d50934abc3ab0145f4fcbf3e2cc Mon Sep 17 00:00:00 2001 From: seahi Date: Sun, 8 Sep 2024 21:14:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=93=E5=8D=B0=E7=9F=A9=E5=BD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Example19.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/Example19.java diff --git a/src/Example19.java b/src/Example19.java new file mode 100644 index 0000000..4f4f74c --- /dev/null +++ b/src/Example19.java @@ -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(); + } + + } +}