[英]Java main not running <terminated>
Just made a simple for loop, was playing around with some integers and was wondering why it keep saying < terminated> and no print output? 只是做了一个简单的for循环,正在处理一些整数,并且想知道为什么为什么一直说<终止>并且没有打印输出?
public class CodingBat {
public static void main(String[] args){
for(int x = 3; x == 0; x--){
System.out.print(x);
}
}
}
When x = 3
then x == 0
is false so it never enters the loop. 当x = 3
x == 0
为假,因此它永远不会进入循环。 Most likely you intended. 您最有可能想要。
for(int x = 3; x >= 0; x--) {
Because of your terminating condition in your for-loop: 由于您在for循环中的终止条件:
x == 0
x
is not 0
, so it won't even run. x
不是0
,所以它甚至不会运行。
You probably wanted: 您可能想要:
for(int x=3; x>0; x--)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.