Java Programming Interview Questions

Spread the love

Java Programming Interview Questions

Fibonacci Series

class FibonacciSeries{  
public static void main(String args[])  
{   
 int s1=0,s2=1,s3, i, s4=10;    
 System.out.print( s1+" "+ s2);    
    
 for(i=2;i<s4;++i)  
 {    
  s3=s1+s2;    
  System.out.print(" "+s3);    
  s1=s2;    
  s2=s3;   
System.out.print(" Java Programming Questions"); 
 }    
}
}
Java Programming Interview Questions

Prime numbers program

public class PrimeNumberProgram{    
 public static void main(String args[]){    
  int i,j=0,flag=0;      
  int k=3;//it is the number to be checked    
  j=k/2;      
  if(k==0||k==1){  
   System.out.println(k+"The given number is not prime number");      
  }else{  
   for(i=2;i<=j;i++){      
    if(k%i==0){      
     System.out.println(k+"The given number is not prime number");      
     flag=1;      
     break;      
    }      
   }      
   if(flag==0)  { System.out.println(k+" The given number is prime number");
System.out.println("Java Programming Interview Questions");
 }  
  }  
}    
}

Factorial program

public class FactorialProgram {   number =a, fact=b

    public static void main(String[] args) {
        int a = 5;
        long b = 1;
        for(int i = 1; i <= a; i++)
        {
            factorial = b * i;
        }
        System.out.println("Factorial of "+a+" is: "+b);

        System.out.println("Java Programming Questions");
    }
}

Armstrong number

public class ArmstrongNumberProgram
{ 
    
    int power(int e, long f)
    {
        if( f == 0)
            return 1;
        if (f%2 == 0)
            return power(e, f/2)*power(e, f/2);
        return e*power(e, f/2)*power(e, f/2);
    }
  
  
    int order(int e)
    {
        int n = 0;
        while (e != 0)
        {
            n++;
            e = e/10;
        }
        return n;
    }
  
  
    boolean isArmstrong (int e)
    {
  
        int n = order(e);
        int temp=e, sum=0;
        while (temp!=0)
        {
            int r = temp%10;
            sum = sum + power(r,n);
            temp = temp/10;
        }
  
          return (sum == e);
    }
  
  
    public static void main(String[] args)
    {
        Armstrong ob = new Armstrong();
        int e = 123;
        System.out.println(ob.isArmstrong(e));
        e = 1234;
        System.out.println(ob.isArmstrong(e));
    }
}

Generate random numbers in java

class RandomNumbersProgram {
  public static void main(String[] args) {
    int d;
    Randoms t = new Randoms();
    
    for (d = 1; d <= 10; d++) {
      System.out.println(t.nextInt(100));
    }
  }
}

Compare two objects in java

public class ObjectComparison  
{  
public static void main(String[] args)   
{  
  
Double a = new Double(456.5555);  
  
Long b = new Long(123456);  
  
System.out.println("Objects are not equal, hence it returns a value of " + a.equals(b));  
System.out.println("Objects are equal, hence it returns a value of " + a.equals(456.5555));  
}  
}

Create object in java

public class CreateObjectJava
{    
void show()    
{    
System.out.println("Hi, this is java programming interview questions");    
}    
public static void main(String[] args)   
{    
  
CreateObjectJava obj = new CreateObjectJava();   
 
obj.show();    
}    
}   

If you have any queries regarding the Java Programming Interview Questions, please comment in the comment section. Help freshers team will respond to your query as soon as possible.

To get instant updates on walk-ins and off-campus jobs into your mobile directly join our Telegram Channel

Other Similar Drives for 2021 and 2020 Batches:

Off-campus Jobs2020 Batch
Software Jobs2021 Batch

Free Online Courses:

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top