JAVA program for generating first 100 prime numbers
Answers
Answered by
1
Program to display first 100 prime numbers
To display the first 100 prime numbers, you can either enter n value as 100 in the above program OR write a program like this:
class PrimeNumberDemo { public static void main(String args[]) { int n; int status = 1; int num = 3; System.out.println("First 100 prime numbers are:"); System.out.println(2); for ( int i = 2 ; i <=100 ; ) { for ( int j = 2 ; j <= Math.sqrt(num) ; j++ ) { if ( num%j == 0 ) { status = 0; break; } } if ( status != 0 ) { System.out.println(num); i++; } status = 1; num++; } } }
To display the first 100 prime numbers, you can either enter n value as 100 in the above program OR write a program like this:
class PrimeNumberDemo { public static void main(String args[]) { int n; int status = 1; int num = 3; System.out.println("First 100 prime numbers are:"); System.out.println(2); for ( int i = 2 ; i <=100 ; ) { for ( int j = 2 ; j <= Math.sqrt(num) ; j++ ) { if ( num%j == 0 ) { status = 0; break; } } if ( status != 0 ) { System.out.println(num); i++; } status = 1; num++; } } }
Mewanshwa:
This looks so complicated
Similar questions
India Languages,
7 months ago
Social Sciences,
7 months ago
History,
7 months ago
Chemistry,
1 year ago
Biology,
1 year ago