ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   SiteMap shows list of All Categories in this site.
Google
 
Categories  >>  Software  >>  Core Java  >>  Java J2EE  >>  Java Related
 
 


 

 
 Core Java interview questions  Core Java Interview Questions
 Advanced Java interview questions  Advanced Java Interview Questions
 Swing interview questions  Swing Interview Questions
 EJB interview questions  EJB Interview Questions
 Servlets interview questions  Servlets Interview Questions
 Struts interview questions  Struts Interview Questions
 JDBC interview questions  JDBC Interview Questions
 JMS interview questions  JMS Interview Questions
 SunOne interview questions  SunOne Interview Questions
 J2EE interview questions  J2EE Interview Questions
 Weblogic interview questions  Weblogic Interview Questions
 Websphere interview questions  Websphere Interview Questions
 Java Networking interview questions  Java Networking Interview Questions
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions
Question
Program to find greatest prime number in n numbers?
 Question Submitted By :: Guest
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Program to find greatest prime number in n numbers?
Answer
# 1
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 ?    0 Yes 2 No
Rajani Nagandla
 
  Re: Program to find greatest prime number in n numbers?
Answer
# 2
Sorry. initialize i=2 directly as 2 is the first prime 
number.. no need of checking for 1.
 
Is This Answer Correct ?    2 Yes 0 No
Rajani Nagandla
 
 
 
  Re: Program to find greatest prime number in n numbers?
Answer
# 3
<----------------- 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 ?    0 Yes 0 No
Manikandan
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
What is data abstraction? Elaborate with example? BMC3
what is the difference between sleep() and Wait()? Accenture4
Write a program to create a binary Tree ?  1
why the constructor should be used in class,if there is no constructor what will happen?  4
why abstract class will have a constructor?  3
How can you sort dates? TCS1
what is the difference between static block and static method Huawei9
How a class can implement an interface? SysArc4
A class can be a subclass of itself? Genesis2
What classes can be used to store arbitrary number of objects ?  1
What are virtual functions?  2
what is the need of the Ajax? iFlex5
What is numeric promotion?  1
what is the difference between HashMap And HashTable? Hexaware3
where is .equals() method and how is it different from == operation <giving some confusing implementation> Is hashing related to these? iFlex4
How u dubugg ur project? iFlex1
What is protected and friendly?  1
What is an enumeration class?  2
what is meant by serialization?  6
what is d difference between deep cloning and shallow cloning in core java? Satyam2
 
For more Core Java Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com