用Random()*1000+1生成1000以内的随机数 用循环就能生成100个 int x; int count=0; for(int i=1;i<=x;i++){ if(x%i==0) count++; }if(count==2) System.out.println(x+"为素数"); 再用循环,判断100个数
import java.io.*; import java.util.*;public class YourTask { private static boolean isPrime( int n ) { // fill in yourself }public static void work( long seed, String fileName ) { PrintWriter writer = new PrintWriter( fileName ); Random r = new Rondom( seed ); int n = 0; try { for( int i = 0; i < 100; i++ ) { n = r.nextInt(); if( isPrime( n ) ) writer.println( n ); } } catch( IOException ioe ) { ioe.printStackTrace(); } writer.close(); } }
用循环就能生成100个
int x;
int count=0;
for(int i=1;i<=x;i++){
if(x%i==0)
count++;
}if(count==2)
System.out.println(x+"为素数");
再用循环,判断100个数
import java.util.*;public class YourTask
{
private static boolean isPrime( int n )
{
// fill in yourself
}public static void work( long seed, String fileName )
{
PrintWriter writer = new PrintWriter( fileName );
Random r = new Rondom( seed );
int n = 0;
try {
for( int i = 0; i < 100; i++ ) {
n = r.nextInt();
if( isPrime( n ) )
writer.println( n );
}
} catch( IOException ioe ) {
ioe.printStackTrace();
}
writer.close();
}
}