Breaking News
Home / Java / Java Tutorials / Write a program to generate Prime Numbers

Write a program to generate Prime Numbers

Prime Number GeneratorIn mathematics, a prime number (or a prime) is a natural number that has exactly two distinct natural number divisors: 1 and itself. The first twenty-five prime numbers are:

2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97

An infinitude of prime numbers exists, as demonstrated by Euclid around 300 BC, though the density of prime numbers within natural numbers is 0. The number 1 is by definition not a prime number. The fundamental theorem of arithmetic establishes the central role of primes in number theory: any nonzero natural number n can be factored into primes, written as a product of primes or powers of different primes (including the empty product of factors for 1). Moreover, this factorization is unique except for a possible reordering of the factors.

<!Prime Number Generator Program

The following program shows how to generate Prime Numbers up to a given number. It also prints how many prime numbers are being generated up to that given number.

 

Program Output

Generate Prime Numbers up to : 100
Prime – 2
Prime – 3
Prime – 5
Prime – 7
Prime – 11
Prime – 13
Prime – 17
Prime – 19
Prime – 23
Prime – 25
Prime – 29
Prime – 31
Prime – 35
Prime – 37
Prime – 41
Prime – 43
Prime – 47
Prime – 49
Prime – 53
Prime – 55
Prime – 59
Prime – 61
Prime – 65
Prime – 67
Prime – 71
Prime – 73
Prime – 77
Prime – 79
Prime – 83
Prime – 85
Prime – 89
Prime – 91
Prime – 95
Prime – 97
The number of primes <= 100 is 34

 [pb_builder]

Check Also

Have a Question

How to select a JVM Analyzing Tool?

A JVM monitoring tool also know as a Diagnostic might be needed to fine tune …

Advertisment ad adsense adlogger