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
Why java is considered as platform independent?
How do I enable java in safari?
Is namespace same as package in java?
What is object in java?
What Is Query Throttling in java?
A non-static inner class may have object instances that are associated with instances of the class’s outer class. A static inner class does not have any object instances.
Differentiate between == and equals().
Detail discussions on JVM, memory management and garbage collector.
What is meant by class loader? How many types are there?
what r advatages of websphere? & how to deploy?
Explain what pure virtual function is?
how many types of Inheritance?
how we can make a write-only class in java?
Why is stringbuffer not immutable?
Why is inheritance used in java?