Write a JAVA Program to prime number
from an array of numbers.
import java.io.*;
public class a17 {
public static boolean isprime (int
n)
{
for(int i=2;i<=(n/2);i++)
{
if(n%i==0)
return false;
}
return true;
}
public static int readint ()
{
int n=0;
try
{
BufferedReader br = new
BufferedReader(new InputStreamReader(System.in));
n = Integer.parseInt(br.readLine());
}catch(IOException e)
{
System.out.println("input output error");
System.exit(1);
}
return n;
}
public static void main(String
args[])throws IOException{
System.out.println("enter the size of array");
int n = a17.readint();
int a[]=new int[n];
for(int i=0;i<n;i++){
System.out.println("enter "+
i+"th number");
a[i] = a17.readint();}
for(int i=0;i<n;i++)
{
System.out.println(a[i]);
}
for(int i=0;i<n;i++){
if(!a17.isprime(a[i]))
System.out.println(a[i] +
"is not prime ");
else
System.out.println(a[i] +
"is prime ");
}}}
OUTPUT:
enter the size of array
3
enter 0th number
22
enter 1th number
11
enter 2th number
33
22
11
33
22is not prime
11is prime
33is not prime