📄 prime.java
字号:
import javax.swing.JOptionPane;
public class Prime
{
public static void main(String args[])
{
int k;
int i;
int j;
int n = 0;
String input;
int count = 0;
String output ="";
input = JOptionPane.showInputDialog("please input the count of prime numbers:");
n = Integer.parseInt(input);
int a[];
a = new int[1001];
for (i = 2;; i++)
{
k = (int)Math.sqrt(i);
for (j = 2; j <= k;j++)
{
if (i % j == 0)
break;
}
if (--j == k )
{
++count;
a[count] = i;
if (count == n)
break;
}
}
if (n <= 10)
for (i = 1; i <= n; i++)
output += a[i] + "\n";
else
{
for (i = 1; i <= 5; i++)
output += a[i] + "\n";
output += "...\n";
for (i = n-4; i <= n; i++)
output += a[i] + "\n";
}
output += "The " + n + "-th prime number is" + a[--i];
JOptionPane.showMessageDialog(null, output,"results",JOptionPane.PLAIN_MESSAGE);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -