本文主要是介绍题目:求100以内的素数,全部打印出来。,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目:求100以内的素数,全部打印出来。
public class ZhaoSuShu {public static void isPrime1(){int i,j,count = 0;//System.out.println("2");for(i = 1; i <= 100; i++){for(j = 2; j <= i; j++){if(i % j == 0){break;}}if(j == i){count++;System.out.print(i + " ");if(count % 5 == 0){System.out.println();}}}}public static void isPrime2(){int i,j,count = 0;boolean flag;for(i = 1; i <= 100; i++){flag = true;for(j = 2; j <= Math.sqrt(i); j++){if(i % j == 0){flag = false;break;}}if(i != 1 && flag == true){count++;System.out.print(i + " ");if(count % 5 == 0){System.out.println();}}}}public static void main(String[] args) {// TODO Auto-generated method stubisPrime1();// isPrime2();}}
这篇关于题目:求100以内的素数,全部打印出来。的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!