Introduction
In this blog, I will explain about prime number program, using Java. It is very simple in Java programming. The output will be displayed in the Run module.
Software Requirement
JDK1.3.
Simple Program
- import java.io.*;
-
- class prime
- {
- public static void main(String arg[]) throws IOException
- {
- int i,n;
- String s;
-
- DataInputStream dr = new DataInputStream(System.in);
-
- System.out.println("Enter the Number : ");
- s = dr.readLine();
- n = Integer.parseInt(s);
-
- i=2;
-
- while(i<=n-1)
- {
- if(n%i==0)
- {
- System.out.println("The given number is not a Prime");
- }
- i++;
- }
-
- if(n==i)
- {
- System.out.println("The given number is Prime");
- }
-
- }
- }
Explanation
In this blog, I explained about prime number program, using Java. The output will be displayed in the Run module.
Output