举例如下:
public class test03 {
public static void main(String[] args) {
//打印101-150之间的所有质数
//使用了自定义lable outer
outer: for (int i = 101; i <=150; i++) {
//自然数N不能被〔N/2〕以内的任一整数整除,则自然数N为素数
// 注:〔N/2〕为N/2的整数部分
for (int j = 2; j < i / 2; j++) {
if (i%j==0){
continue outer;
}
}
System.out.print(i+" ");
}
}
}
输出结果