Program to find greatest prime number in n numbers?
Answer Posted / manikandan
<----------------- Import appropriate pkgs ------------->
public class Mainmain
{
public static void main(String[] args) throws IOException
{
BufferedReader br= new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter the no of nos");
int n=Integer.parseInt(br.readLine());
int[] a= new int[n];
System.out.println("Enter the nos");
for(int i=0;i<n;i++)
{
a[i]=Integer.parseInt(br.readLine());
}
Arrays.sort(a);
LOOP: for(int i=n-1;i>=0;i--)
{
int b=2;
boolean c=true;
while(b<a[i])
{
if((a[i]%b)==0)
{
c=false;
continue LOOP;
}
b++;
}
if(c)
{
System.out.println("The largest prime no among the
list is "+a[i]);
break;
}
}
}
}
<----------------- It Works -------------------------->
| Is This Answer Correct ? | 9 Yes | 2 No |
Post New Answer View All Answers
How many threads does a core java have?
What are features of java?
What are the two main uses of volatile in Java?
Is it necessary for the port addresses to be unique? Explain with reason.
What is indexof in java?
Explain the difference between throw and throws in java?
What is an exception in java?
Why there are some null interface in JAVA? What does it mean? Give some null interface in JAVA?
Can a class extends itself in java?
Is hashmap thread safe?
Can keyword be used as identifier?
What are streams in java 8?
Can we use return in constructor?
What is namespace in java?
What is array class in java?