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
  1. import java.io.*;
  2. class prime {
  3. public static void main(String arg[]) throws IOException {
  4. int i, n;
  5. String s;
  6. DataInputStream dr = new DataInputStream(System.in);
  7. System.out.println("Enter the Number : ");
  8. s = dr.readLine();
  9. n = Integer.parseInt(s);
  10. i = 2;
  11. while (i <= n - 1) {
  12. if (n % i == 0) {
  13. System.out.println("The given number is not a Prime");
  14. }
  15. i++;
  16. }
  17. if (n == i) {
  18. System.out.println("The given number is Prime");
  19. }
  20. }
  21. }
Explanation
In this blog, I explained about prime number program, using Java. The output will be displayed in the Run module.

Output
s