While do 输出问题
public class WhileDo
{
public static void main(String[] args)
{
int x = 5;
while(x<10)
{
System.out.print("hello");
//x = x+2;为何注释掉此行没有任何输出结果,不是应该无限次输出吗
}
}
}
2014-11-03 22:30
2014-11-04 08:21
2014-11-04 10:28
2014-11-04 21:35
程序代码:
public class WhileDo
{
public static void main(String[] args)
{
int x = 5;
while(x<10)
{
System.out.print("hello");
x = x+2;
}
}
}
//输出结果:
/*
* hello
* hello
* hello
*/
//解释:x=5,5<10,满足条件,输出hello。
//执行x=x+2;x=7,7<10,满足条件,输出hello。
//执行x=x+2;x=9,9<10,满足条件,输出hello。
//执行x=x+2,x=11,11不小于10,不满足条件,退出循环。
/*
*第二个程序是实现无限循环
*/
public class WhileDo
{
public static void main(String[] args)
{
int x = 5;
while(true)//true为无限循环的条件
{
System.out.print("hello");
x = x+2;
System.out.println(x);//此处输出x的值
}
}
}

2014-11-04 21:54
程序代码:public class WhileDo {
public static void main(String[] args) {
int x = 5;
while (x < 10) {
System.out.print("hello");
System.out.print("\n");
}
}
}
2014-11-05 21:02