} 作者: Lonely_yu 时间: 2015-9-6 17:05
package com.itheima; import java.util.ArrayList; import java.util.Collections; //求三位数的质数,只能被 本身和1整除,倒序输出 public class ExamTest17 { public static void main(String[] args) { ArrayList<Integer> al = new ArrayList<>(); boolean flag = true; for (int a = 100; a < 1000; a++) { flag = true; for (int b = 2; b < a; b++) { if (a % b == 0) { flag = false; break; } } if (flag) { al.add(a); } } Collections.reverse(al); System.out.println(al); } }