我不能得到一个基本的for循环来工作java 8(I cant get a basic for loop to work java 8)
我正在测试循环,当我尝试这个它不起作用:
public static void main(String[] args) { for(int i=0;i==5;i++){ System.out.println(i); } }当我运行这个我希望得到“0,1,2,3,4,5”,但我得到的只是“建立成功”。 我在ubuntu linux上使用netbeans 8.0。 任何帮助或解释为什么将不胜感激。
编辑:*捂脸
I was testing out the loops and when i try this it doesn't work:
public static void main(String[] args) { for(int i=0;i==5;i++){ System.out.println(i); } }When i run this i expect to get "0,1,2,3,4,5" but I get nothing other than "BUILD SUCCESSFUL". I'm using netbeans 8.0 on ubuntu linux. Any help or an explanation why will be appreciated.
EDIT:*facepalm
最满意答案
在Java for循环中,例如while循环,您不指定“break”,而是指定“continue”条件。 因此,您应该将==替换为<= 。
In Java for loops, like while loops, you don't specify a "break", but instead a "continue" condition. Thus, you should replace the == with <=.
更多推荐
发布评论