• While与do...While


    While与do...While

    public class WhileDemo01 {
        public static void main(String[] args) {
            //输出1-100
    
            int i = 0;
            while (i<100){
                i++;
                System.out.println(i);
            }
        }
    }
    


    public class WhileDemo02 {
        public static void main(String[] args) {
            //死循环
            while (true){
                //等待客户端连接
                //定时检查
                //。。。。
            }
        }
    }
    


    public class WhileDemo03 {
        public static void main(String[] args) {
            //计算1+2+3+...+100;
    
            //高斯的故事
    
            int i = 0;
            int sum = 0;
    
            while (i<=100){
                sum = sum + i;
                i++;
            }
    
            System.out.println(sum);
        }
    }
    


    public class DoWhileDemo01 {
        public static void main(String[] args) {
            int i = 0;
            int sum = 0;
    
            //i++和++i的区别
            do {
                sum = sum + i;
                i++;
            }while (i<=100);
    
            System.out.println(sum);
        }
    }
    


    public class DoWhileDemo02 {
        public static void main(String[] args) {
            int a = 0;
            while (a<0){
                System.out.println(a);
                a++;
            }
            System.out.println("===============");
            do{
                System.out.println(a);
                a++;
            }while (a<0);
        }
    }
    

    do while与while的区别

  • 相关阅读:
    nginx缓存
    java 常用命令工具
    shell流程控制--循环语句
    Python 文档 涉及词汇
    python 学习网站
    python web入门程序
    编译安装 Python3.6.1
    正则表达式与grep
    编译安装 Nginx1.12.1
    查看进程号
  • 原文地址:https://www.cnblogs.com/helloxiaolu/p/13255212.html
Copyright © 2020-2023  润新知