Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

How do you delete a list in java?

935


Why method overriding is used?

1069


What are local variables?

1030


how to open and edit XML file in Weblogic???

1960


What is Major and importance difference between for and foreach loop ?

1119


What do you mean by ternary operator in java?

1003


What does void * mean?

1012


What is skeleton and stub?

1059


What is mnemonic in assembly language?

1055


How do you use compareto in java?

962


How can we find the sum of two linked lists using stack in java?

1120


What is the difference between C++ and Java and your preferences?

1103


What does null mean in java?

1048


What is the symbol for average?

1013


What does g mean in regex?

974