方法
设计方法原则:方法的本意是功能块,就是实现某个功能的语句块的集合。设计方法的时候最高保持方法的原子性,就是一个方法只完成一个功能,利于后期的扩展。
package com.shangxuetang.chapter7;
public class TestBreakContinue {
public static void main(String[] args) {
//测试break与continue
test02();
test01();
}
public static void test01() {
//输出100-150之间不能被3整除的整数
for (int m = 100; m <= 150; m++) {
if (m % 3 == 0) {
continue;
}
System.out.println(m);
}
}
public static void test02() {
//随机整数如果是88则跳出循源并输出整个循环次数
int total = 0;
System.out.println("begin");
while (true) {
total++;
//Math.round 取整方法
int random = (int) Math.round(Math.random() * 100);
if (random == 88) {
break;
}