public class Test
{
public static void main(String[] args)
{
final int NUMBER_OF_PRIMES = 50;
final int NUMBER_OF_PRIMES_PER_LINE = 10;
int count = 0;
int number = 2;
int[] array = new int[NUMBER_OF_PRIMES];
System.out.println("The first 50 prime numbers are: ");
while(count < NUMBER_OF_PRIMES)
{
boolean isPrime = true;
for(int divisor = 2; divisor <= Math.pow(number, 0.5); divisor++)
{
if(number % divisor == 0)
{
isPrime = false;
break;
}
}
if(isPrime == true)
array[count++] = number;
number++;
}
for(int i = 0; i < 50; i++)
{
if((i + 1) % NUMBER_OF_PRIMES_PER_LINE == 0)
System.out.println(array[i]);
else
System.out.print(array[i] + " ");
}
}
}6-6 编程练习题答案
寻找50个质数:一种高效的算法实现
最新推荐文章于 2018-11-30 20:22:52 发布
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
EmotiVoice
AI应用
EmotiVoice是由网易有道AI算法团队开源的一块国产TTS语音合成引擎,支持中英文双语,包含2000多种不同的音色,以及特色的情感合成功能,支持合成包含快乐、兴奋、悲伤、愤怒等广泛情感的语音。
1534

被折叠的 条评论
为什么被折叠?



