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 do you delete a list in java?
Why method overriding is used?
What are local variables?
how to open and edit XML file in Weblogic???
What is Major and importance difference between for and foreach loop ?
What do you mean by ternary operator in java?
What does void * mean?
What is skeleton and stub?
What is mnemonic in assembly language?
How do you use compareto in java?
How can we find the sum of two linked lists using stack in java?
What is the difference between C++ and Java and your preferences?
What does null mean in java?
What is the symbol for average?
What does g mean in regex?