package com.fqs.demo; public class ZhiNumber { public static void main(String[] args) { //计算某个数是否是质数 能被1和自身除时余数为0 ;被其他数除余数不等于0 int number=4; int count=0; Boolean flag=true; for(int index=2;index<number;index++) { if(number%(index)!=0) { System.out.println("质数(被2,或自身之间的数)除,余数不等于0,第"+index+"次是质数"); flag=true; }else { System.out.println("第"+index+"次,能被整除,不是质数"); flag=false; count++; break; } }//结束循环 if(count==0) { System.out.println("恭喜,"+"number:"+number+"是质数"); }else { System.out.println("抱歉,"+"number:"+number+"不是质数"); } }//结束主方法 }//结束类
标签:index,int,质数,是否是,某个,余数,public From: https://www.cnblogs.com/haha1988/p/17058706.html