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

What is output buffer?

977


What does replaceall do in java?

869


What is the difference between class & structure?

1120


What is a class reference?

1016


Explain about data types?

1000


What is busy spin, and why should you use it?

1022


Does string isempty check for null?

962


According to java operator precedence, which operator is considered to be with highest precedence?

1034


What does system.gc() and runtime.gc() methods do?

990


Explain thread in java?

1093


What is variable argument in java?

948


What is this keyword in java?

983


When does a class need a virtual destructor?

950


What is the difference between path and classpath variables?

965


Explain about oops concepts.

1068