0
点赞
收藏
分享

微信扫一扫

for循环的几种写法

waaagh 2022-05-04 阅读 62
java

第一种 

public class Test{
    public static void main(String[] args){

        for (int i=1;i<=10;i++){
            System.out.println("hello world"+i);
       }


    }
}

第二种

public class Test{
    public static void main(String[] args){

        for (int i=1;i<=10;){
            System.out.println("hello world"+i);
            i++;
        }

    }
}

第三种 

public class Test{
    public static void main(String[] args){

        int i=1;
        for (;i<=10;){
            System.out.println("hello world"+i);
            i++;
        }

    }
}

 

第四种

public class Test{
    public static void main(String[] args){

        int i=1;
        for (;;){
            if (i>10) {
                break;
            }
            System.out.println("hello world"+i);
            i++;
        }


    }
}

 

 

举报

相关推荐

0 条评论