java 中的while 和 do while for循环
来源:互联网 发布:vb工控软件开发 编辑:程序博客网 时间:2024/05/17 09:43
while循环:
句式:
while(条件){
代码
}
只有当条件为true时 才会执行while循环 否则执行while后面的语句
代码案例如下:
package Lei;
public class Test03 {
public static void main(String[] args){
int i=65;
while(i<=65+25){
System.out.println((char)i+":"+i);
i++;
}
}
}
public static void main(String[] args){
int i=65;
while(i<=65+25){
System.out.println((char)i+":"+i);
i++;
}
}
}
结果如下:
A:65
B:66
C:67
D:68
E:69
F:70
G:71
H:72
I:73
J:74
K:75
L:76
M:77
N:78
O:79
P:80
Q:81
R:82
S:83
T:84
U:85
V:86
W:87
X:88
Y:89
Z:90
B:66
C:67
D:68
E:69
F:70
G:71
H:72
I:73
J:74
K:75
L:76
M:77
N:78
O:79
P:80
Q:81
R:82
S:83
T:84
U:85
V:86
W:87
X:88
Y:89
Z:90
解法2 :
package Lei;
public class Test03 {
public static void main(String[] args){
char c='A';
while(c<='Z'){
System.out.println(c+":"+(int)c);
c++;
}
}
}
public static void main(String[] args){
char c='A';
while(c<='Z'){
System.out.println(c+":"+(int)c);
c++;
}
}
}
结果如下:
A:65
B:66
C:67
D:68
E:69
F:70
G:71
H:72
I:73
J:74
K:75
L:76
M:77
N:78
O:79
P:80
Q:81
R:82
S:83
T:84
U:85
V:86
W:87
X:88
Y:89
Z:90
B:66
C:67
D:68
E:69
F:70
G:71
H:72
I:73
J:74
K:75
L:76
M:77
N:78
O:79
P:80
Q:81
R:82
S:83
T:84
U:85
V:86
W:87
X:88
Y:89
Z:90
用 do while 输出所有小写字母
package Lei;
public class Test03 {
public static void main(String[] args){
char c='a';
do{
System.out.println(c+":"+(int)c);
c++;
}
while(c<='z');
}
}
public static void main(String[] args){
char c='a';
do{
System.out.println(c+":"+(int)c);
c++;
}
while(c<='z');
}
}
结果如下:
a:97
b:98
c:99
d:100
e:101
f:102
g:103
h:104
i:105
j:106
k:107
l:108
m:109
n:110
o:111
p:112
q:113
r:114
s:115
t:116
u:117
v:118
w:119
x:120
y:121
z:122
b:98
c:99
d:100
e:101
f:102
g:103
h:104
i:105
j:106
k:107
l:108
m:109
n:110
o:111
p:112
q:113
r:114
s:115
t:116
u:117
v:118
w:119
x:120
y:121
z:122
1 for循环格式:
for(初始条件(可以多个):循环判断条件(true时执行循环);循环条件变量变更(加或者减))
{
循环代码
}
package Lei;
public class Test03 {
public static void main(String[] args){
char c='a';
for(;c<='z';c++)
{
System.out.println(c+":"+(int)c);
}
}
}
public static void main(String[] args){
char c='a';
for(;c<='z';c++)
{
System.out.println(c+":"+(int)c);
}
}
}
结果如下:
a:97
b:98
c:99
d:100
e:101
f:102
g:103
h:104
i:105
j:106
k:107
l:108
m:109
n:110
o:111
p:112
q:113
r:114
s:115
t:116
u:117
v:118
w:119
x:120
y:121
z:122
b:98
c:99
d:100
e:101
f:102
g:103
h:104
i:105
j:106
k:107
l:108
m:109
n:110
o:111
p:112
q:113
r:114
s:115
t:116
u:117
v:118
w:119
x:120
y:121
z:122
阅读全文
0 0
- java 中的while 和 do while for循环
- Java循环for, while和do...while
- java/while和do-while循环,for循环
- Java循环for, while和do...while & Java决策制定
- while和do..while和for循环
- Java中循环有三种形式 while、do-while 和 for
- Java 循环结构for、do...while、while
- Java while,do while, for 循环浅析
- java:for while do while循环
- java for,while,do while循环
- JavaScript中的while和do while循环
- Java中的Do-while循环
- while、do while、for循环
- 循环:for、while、do-while
- C#中的三种循环:while、do..while..、for循环
- while循环、do..while 循环、for循环
- for循环,do....while循环,while循环
- for循环,while循环,do while循环
- 重建二叉树
- hibernate.cfg.xml文件配置标签详解
- CV资源整理
- 一.Java对象导论——Java编程思想第4版学习笔记
- 十大Web应用安全风险
- java 中的while 和 do while for循环
- Java思维导图(6)--集合类
- 文章标题
- 线段树(基础)
- PHP中文乱码的问题解决
- jquery实现微信中长按识别二维码
- 英语常用的62个英语句型,学英语须掌握
- linux系统上安装java
- 队列优化(链式)