do-while与while
程序员文章站
2024-03-23 23:16:34
...
1.do-while
public class Text1{
public static void main(String[] args){
int i=1;
do{
System.out.println(i);
i+=2;
} while(i<=100);
}
}
2.while
public class Text2{
public static void main(String[] args){
int i=1;
while(i<=100){
i+=2;
System.out.println(i);
}
}
}
do-while先执行命令再判断,while先判断再执行命令。
转载于:https://blog.51cto.com/11269674/1860419
上一篇: while与do-while的区别
下一篇: while与do while 的区别