• while...break 实例


    // 输出1-100内前5个可以被3整除的数
    public class Demo {
        public static void main(String[] args) {
            int num = 0;
    
            for (int i =1; i <= 100; i++) {
                if (i % 3 == 0) {
                    System.out.println(" " + i);
    
                    num++;
                }
                if (num == 5) {
                    break;
                }
    
            }
        }
    }

    输出: 3 6 9 12 15

    //输出101-200内的质数
    public class study {
        public static void main(String[] args) {
            for (int i = 101; i < 200; i++) {
                boolean f = true;
                for (int j = 2; j < i; j++) {
                    if (i % j == 0) {
                        f = false;
                        break;
                    }
                }
                if (!f) {
                    continue;
                }
                System.out.print(" " + i);
            }
    
        }
    
    }

    输出: 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199

  • 相关阅读:
    积累
    AnkhSVN使用记录
    时间戳
    Nhibernate
    Css的sb问题
    ajax
    WAS资料收集
    CryStal资料收集
    Decorator模式
    MSDN WebCast网络广播全部下载列表
  • 原文地址:https://www.cnblogs.com/fanren224/p/8457226.html
Copyright © 2020-2023  润新知