Java Programs for selenium Interview

  • by

Java Programs for selenium Interview:-
During the job hunting following are the java programming questions surely asked you in selenium interview. I know most of the programs you have prepared  in graduation itself. Here we are providing some programs to crack your selenium interview.
1] Program to print Factorial number in java
package basic;
public class Factorial {
public static void main(String[] args) {
// by decrement *
int k = 5;
int fact = 1;
for (int i= 5 ; i>= 1; i–){
fact = fact * i;
}
System.out.println(fact);
// by increment
int a = 8;
int ft = 1;
for (int b= 1 ; b<= 8; b++){
ft = ft * b;
}
System.out.println(ft);
}
}

2] Program to print Reverse string using and without using reverse function
package basic;
public class StringRev {
public static void main(String[] args) {
/*StringBuffer buffer = new StringBuffer(“Kumar”);
buffer.reverse();
System.out.println(buffer);
*/
String str =”Shweta”;
for(int i=str.length()-1; i>=0; i–)
{
System.out.print(str.charAt(i));
}
}
}

3] Program for Fibonacci series number in java
package basic;
public class Febonaci {
public static void main(String[] args) {
int x = 0;
int y = 1;
int count = 10;
int z;
System.out.println(x+”\n”+y);
for (int i = 2; i <count; i++){
z= x + y;
System.out.print(z);
x = y;
y = z;
}
}
}

4] Print Prime number in java
package basic;
public class PrimeNumb {
public static void main(String[] args)
{
int num=9;
int i;
for( i=2; i<num; i++)
{
if(num%i==0)
{
break;
}
}
if(num==i)
{
System.out.println(“number is prime”);
}
else
{
System.out.println(“number is not prime”);
}
}
}

5] Programe for Palindrome in java
package basic;
public class Palindrome {
public static void main(String[] args) {
String str = “Kumar”;
int i=0;
int j= str.length()-1;
while(i<j)
{
if(str.charAt(i)!=str.charAt(j))
{
break;
}
else
{
i++;
j–;
}
}
if(i<j)
{
System.out.println(“String is not palindrome”);
}
else
{
System.out.println(“String is palindrome”);
}
}
}

Leave a Reply