Welcome To The World Of Java

This site will teach you the basics of Java. It is not necessary to have any prior programming experience.

Java program to test the Prime number.

Somdeb Burman | 11:14:00 AM | 0 comments


import java.util.*;
class Prime {
 public static void main(String args[]) {
  int flag, x, i;
  flag = 0;
  int a[] = new int[7];
  for (x = 0; x < args.length; x++) {
   a[x] = Integer.parseInt(args[x]);
   for (i = 2; i < (a[x] / 2); i++) {
    if ((a[x] % i) == 0) {
     break;
    } else flag = 1;
   }
   if (flag == 1)
    System.out.println(a[x] + " is a prime no ");
   else
    System.out.println(a[x] + " is not a prime no ");
   flag = 0;
  }
 }
}

Java Resources are available for Download from below

Category: , , , ,

0 comments