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?

Answers were Sorted based on User's Feedback



Program to find greatest prime number in n numbers?..

Answer / rajani nagandla

Sorry. initialize i=2 directly as 2 is the first prime
number.. no need of checking for 1.

Is This Answer Correct ?    10 Yes 3 No

Program to find greatest prime number in n numbers?..

Answer / 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

Program to find greatest prime number in n numbers?..

Answer / rajani nagandla

1.Read n
2.lets take variables of type int (i=1,j=1,temp=0,count=0);
3. for (;i<n;i++){
count=0;
while(j<=i){
if((i%j)==0){
count+=1;
j++;
if(count>2)break;
}
}
if(count==2)
temp=i;
}
4.the value in temp after for loop execution will be the
Greatest Prime Number

Is This Answer Correct ?    6 Yes 5 No

Post New Answer

More Core Java Interview Questions

how do you store phone numbers using java collections

5 Answers   Bosch, IBAB,


What is the flag in java?

0 Answers  


How many digits can a float hold?

0 Answers  


when we create singleton design then we create private constructtor..so how JVM take private constructor to make object..but it's private..

1 Answers   Ness Technologies,


Advantages of Inheritance in java.

11 Answers   CybAge, HCL,


Is hashset ordered?

0 Answers  


What is predicate in java?

0 Answers  


Why java doesn’t support multiple inheritances?

0 Answers  


What modifiers are used with an inner class which is a member of an outerclass?

1 Answers  


What is a arraylist in java?

0 Answers  


What is the difference between Error, defect,fault, failure and mistake?

0 Answers   HCL,


Why put method is used?

0 Answers  


Categories