1、本篇博客主要介绍几道for循环嵌套练习题目
2、源码如下
复制代码
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118class ForForTest { public static void main(String[] args) { /* ***** **** *** ** * */ /* int z = 5; for (int x = 1; x<=5 ;x++ )//1-5 1-4 1-3//1-5 2-5 3-5 { for (int y=1; y<=z ; y++ ) { System.out.print("*"); } System.out.println(); z--; } */ /* int z = 1; for (int x = 1; x<=5 ;x++ )//1-5 1-4 1-3//1-5 2-5 3-5 { for (int y=z; y<=5 ; y++ ) { System.out.print("$"); } System.out.println(); z++; } */ for(int x=1; x<=5; x++) { for(int y=x; y<=5; y++) { System.out.print("*"); } System.out.println(); } /* * ** *** **** ***** */ System.out.println("----------"); for (int x=1; x<=5 ;x++ ) { for (int y=1;y<=x ;y++ ) { System.out.print("*"); } System.out.println(); } System.out.println("----------"); /* 54321 5432 543 54 5 */ for (int x=1; x<=5; x++ ) { for (int y=5; y>=x ;y-- ) { System.out.print(y); } System.out.println(); } System.out.println("----------"); /* 1 22 333 4444 55555 */ for (int x=1; x<=5 ; x++) { for (int y=1;y<=x ;y++ ) { System.out.print(x); } System.out.println(); } } }
最后
以上就是激昂手套最近收集整理的关于Java基础之for循环嵌套练习(一)的全部内容,更多相关Java基础之for循环嵌套练习(一)内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复