Find out the prime number in java

Posted By: Java Examples - 6:02 PM


& Comment

 Prime number

We will be read how to get prime number between 1 to given number. First of all we have to define a class "primenum ". Java  util package has a input  in which  Scanner input=new Scanner(  is used for reading the input stream . As in this program we are going to insert certain instruction by creating  Scanner class.
Now applying in this program we use two 'for' loop. For loop will start from 1 to entered number. And another loop will start and divide it from 2 to less than those number. If number is divided by any number that means it is not prime otherwise prime number.

Source Code

import java.util.Scanner;
public class primenum {
int n;
public primenum()
Scanner input=new Scanner(;
System.out.println("Enter the Number");
public void assignprime()
int i;
for (i=2;i<n;i++)
System.out.println("This is not Prime number");
System.out.println("This is Prime number");
public static void main (String args[])
primenum prime=new primenum();



About Java Examples

I’m passionate about Web Development and Programming and I go to extreme efforts to meet my passion. I’m a believer of learning the fundamentals first. I try to understand everything little bit more than the average.


Post a Comment

Thank you for vising

Copyright © 2016 Java Examples ACHCHUTHAN.ORG. Designed by Templateism .