java流程控制之 while 循环 1到100的和



package struct;

public class Demo03 {
    public static void main(String[] args) {
        text();
        System.out.println("------------");
        text2();
    }

    public static void text() {
        int i = 0;
        while (i < 100) {
            i++;
            System.out.println(i);
        }
    }

    public  static  void  text2(){
        int i=0;
        int sum=0;

        while (i<=100){
            sum+=i;
            i++;

        }
        System.out.println(sum);
    }
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM