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
What is output buffer?
What does replaceall do in java?
What is the difference between class & structure?
What is a class reference?
Explain about data types?
What is busy spin, and why should you use it?
Does string isempty check for null?
According to java operator precedence, which operator is considered to be with highest precedence?
What does system.gc() and runtime.gc() methods do?
Explain thread in java?
What is variable argument in java?
What is this keyword in java?
When does a class need a virtual destructor?
What is the difference between path and classpath variables?
Explain about oops concepts.