Java program to Print Prime numbers 1 to n

To find a given input number is prime.,

Iterate each number from 2 to half of input number, and check whether each iteration number divides the input number. (If no number divides, the input number is prime)

We can check whether the number is divisible by using modulo (%) function, so that if number is divisible, then result will be 0, else it will return 1.

Leave a Reply

Your email address will not be published. Required fields are marked *