我是靠谱客的博主 高高草莓,这篇文章主要介绍java打印小人走楼梯,现在分享给大家,希望可以做个参考。

小人走楼梯。

利用嵌套的for循环语句自定义台阶数

复制代码
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// 小人走台阶 package class_experiment_questions; import java.util.Scanner; public class steps_walking { public static void main(String[] arg) { // 用户自定义输入台阶数量 Scanner in = new Scanner(System.in); System.out.print("请输入台阶的数量:"); int amount=in.nextInt(); for(int i=1;i<=amount;i++) { for (int k = 1; k <= 5*(amount-i)+2; k++) { System.out.print(" "); } System.out.print("O ******"); for (int k = 1; k <= 5*(i-1); k++) { System.out.print(" "); } System.out.println("*"); for (int k = 1; k <= 5*(amount-i)+1; k++) { System.out.print(" "); } System.out.print("/|\ *"); for (int k = 1; k <= i*5; k++) { System.out.print(" "); } System.out.println("*"); for (int k = 1; k <= 5*(amount-i)+1; k++) { System.out.print(" "); } System.out.print("/ \ *"); for (int k = 1; k <= 5*i; k++) { System.out.print(" "); } System.out.println("*"); } for (int k = 1; k <= amount*5+7; k++) { System.out.print("*"); } // 改进:使用repeat简化代码 // public static void main(String[] args) // { // print_people(); // System.out.println("*".repeat(32)); // } // public static void print_people() // { // for (int i=21;i>=1;i=i-5) // { // System.out.println(" ".repeat(i) // +" O ******" // +" ".repeat(21-i) // +"*"); // System.out.println(" ".repeat(i) // +"/|\ *" // +" ".repeat(26-i) // +"*"); // System.out.println(" ".repeat(i) // +"/ \ *" // +" ".repeat(26-i) // +"*"); // // } // } } }

最后

以上就是高高草莓最近收集整理的关于java打印小人走楼梯的全部内容,更多相关java打印小人走楼梯内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(78)

评论列表共有 0 条评论

立即
投稿
返回
顶部