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

Why java is considered as platform independent?

1002


How do I enable java in safari?

1033


Is namespace same as package in java?

984


What is object in java?

985


What Is Query Throttling in java?

997


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.

1014


Differentiate between == and equals().

1047


Detail discussions on JVM, memory management and garbage collector.

985


What is meant by class loader? How many types are there?

1251


what r advatages of websphere? & how to deploy?

2193


Explain what pure virtual function is?

1021


how many types of Inheritance?

1171


how we can make a write-only class in java?

1023


Why is stringbuffer not immutable?

1079


Why is inheritance used in java?

1121