Java program to find prime numbers from array

Prime numbers from array

Java program to find prime numbers from array.Prime numbers are those which are divisible only by itself and 1.

import java.util.*;
class scan
{
public static void main(String arg[])
{
int j,i,y,count;
int x[]=new int[100];
Scanner kb=new Scanner(System.in);
System.out.println("Enter size of array");
y=kb.nextInt();
System.out.println("Enter elements in array");
for(i=1;i<=y;i++)
{
 x[i]=kb.nextInt();
}

System.out.println("Prime numbers are:- ");
  for(i=1;i<=y;i++)
{      
     count=0;
      for(j=2;j<=x[i]/2;j++)
      {
	   if(x[i]%j==0)
	   {
	   count++;
	   break;
	   }
      }

      if(count==0)
      {

       System.out.println(x[i]);
      }


}

}
}

Output

Prime numbers from array


Comment below if you are facing any problem and subscribe to our newsletter for latest update.


Also read

Java Program to enter Elements of your choice in Array
Java simple program to sort entered element in the Array
Java program to insert an element into sorted array

Summary
Java program to find prime numbers from array
Article Name
Java program to find prime numbers from array
Description
The article shows program to find prime numbers from array.Prime numbers are those which are divisible only by itself and 1.
Author
Publisher Name
Scanfcode
Publisher Logo

Leave a Reply

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