SUBSCRIBE HERE TO GET POST UPDATES VIA EMAIL :

Delivered by FeedBurner

Java Questions For Selenium WebDriver Interview

Part 5

21 : Explain System.out.println();

Answer :
  • System : is a final class in  java.lang package.
  • out : is a static member of system class. It is an instance of java.io.PrintStream. This stream is already open and ready to accept output data.
  • println : is a method of java.io.PrintStream .It is an overloaded method.

22 : Write program to print fibonacci series 0, 1, 1, 2, 3, 5, 8, 13, 21,... 

Answer :
public class fibonaccci {

 public static void main(String[] args) {
  int f1 = 0;
  int f2 = 1;
  int sum = 0;
  for(int i=0; i<=21;){
   System.out.println(f1);
   sum = i+f2;
   f2=i;
   f1=sum;
   i=f1;
  }
 }
}

23 : Write program to get result of 52+42-32+22-1 

Answer :
public class SquareSum {

 public static void main(String[] args) {
  
  int sum = 0;  
  for (int i=5;i>=1;i--){      
   if(i%2!=0){
    if(sum<(i*i)){
     sum = (i*i)-sum;
    }else{
     sum = sum-(i*i);
    }    
   }else{    
    sum = sum+(i*i);
   }    
  }
  System.out.println(sum);
 }
}

24 : What is return type of testng @DataProvider annotation method? 

Answer : It will return double object array “Object[][]”.

25 : int x=10 and y=20. Swap both variable values without using any temp variable.

Answer :
public class swapNumbers {

 public static void main(String[] args) {
  
  int x = 10;
  int y = 20;
  
  System.out.println("Before swapping x = " + x + " and y = " + y);

  x = x + y;
  y = x - y;
  x = x - y;

  System.out.println("After swapping x = " + x + " and y = " + y);
 }
}

No comments:

Post a Comment