HomeJava

Write a program to print first n prime numbers in java

Write a program to print first n prime numbers in java
Like Tweet Pin it Share Share Email

In this program you will be making use of methods and creating an object of a class and calling the method. So you will see one method by name “isPrime” which takes an integer as an input and returns a boolean value, the returned boolean value evaluates to true if the given input number is a prime and evaluates to false if its not a prime number.

There may be more efficient ways of printing the first n prime numbers, we have tried to give the simplest way of doing the same, please feel free to share any queries in form of comments, we would be more than happy to help.

Comments (0)

Leave a Reply

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