forked from CPU-Code/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrint_rectangle.java
More file actions
52 lines (46 loc) · 1018 Bytes
/
Print_rectangle.java
File metadata and controls
52 lines (46 loc) · 1018 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package src.cycle;/*
* @Author: cpu_code
* @Date: 2020-07-07 11:20:48
* @LastEditTime: 2020-07-07 11:21:42
* @FilePath: \java\basics\print_rectangle.java
* @Gitee: https://gitee.com/cpu_code
* @CSDN: https://blog.csdn.net/qq_44226094
*/
/**
* 使用方法时实现打印三个长宽不同的矩形
*
*****
*****
*****
****
****
**********
**********
**********
**********
**********
**********
*/
public class Print_rectangle
{
public static void main(String[] args)
{
printRectangle(3, 5); // 调用 printRectangle()方法实现打印矩形
printRectangle(2, 4);
printRectangle(6, 10);
}
// 下面定义了一个打印矩形的方法,接收两个参数,其中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.print("\n");
}
}