我不能得到一个基本的for循环来工作java 8(I cant get a basic for loop to work java 8)

编程入门 行业动态 更新时间:2024-10-24 16:29:05
我不能得到一个基本的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 <=.

更多推荐

本文发布于:2023-07-05 07:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1034453.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:工作   java   basic   loop   work

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!