A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

  1. /*
  2. *
  3. * 第五题:编程打印所有的3位质数,质数特点:只能被1和其本身整除
  4. *
  5. */


  6. package com.itheima;

  7. public class Test5 {

  8.         public static void main(String[] args) {
  9.        
  10.                 // 定义一个三位数i
  11.                 for(int i=100;i<=999;i++){
  12.                         int n=0,k=0;
  13.                         for(int j=1;j<(i+1)/2;j++)
  14.                         {
  15.                                 if((i%j)==0)
  16.                                         n++;
  17.                                                                                 }
  18.                         if(n<2){
  19.                                 System.out.print(i+" ");
  20.                                k++;
  21.                                //每隔五个换行
  22.                            if(k%5==0)
  23.                                 System.out.println();}                               
  24.                                                                                 }
  25.                        
  26.                                                                 }
  27. }
复制代码

3 个回复

倒序浏览
我是想每隔五个就开始换行,但是好像怎么换都换不了
回复 使用道具 举报
因为你n<2
回复 使用道具 举报

有好的建议不
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马