Most important java program interview Questions.

The most important java program interview questions to crack the interview.

Write a program to print 1 to 10?

public class Main{
public static void main(String args[]){

int n=10;
int i;
for(i=1;i<=n;i++){
System.out.println(i);
}
}
}

Write a program to print * pattern?

public class Main{
public static void main(String args[]){
int n=10;
int i;
int j;
for(i=1;i<=n;i++){
for(j=1;j<=i;j++){
System.out.print(“*”);
}
System.out.println(“”);
}
}
}

Write a program to print even number?

public class Main{
public static void main(String args[]){
int n=10;
int x;
x=n%2;
if(x==0){
System.out.println(“even”);
}
else{
System.out.println(“odd”);
}
}
}

Write a program of prime number?

public class Main{
public static void main(String args[]){
int n=7;
int c=0;
int i;
for(i=1;i<=n;i++){
if(n%i==0){
c++;
}

}
if(c==2){
System.out.println(“prime number”);
}
else{
System.out.println(“Not prime number”);
}
}
}

SQL query interview questions for both freshers and experienced.

Write a program of palindrome?

public class Main{
public static void main(String args[]){
int n=121;
int m=121;
int r=0;
int d;
while(n>0){
d=n%10;
n=n/10;
r=r*10+d;
}
if(r==m){
System.out.println(“palindrom”);
}
else{
System.out.println(“not palindrom”);
}
}
}

Write a program of factorial?

public class Main{
public static void main(String args[]){
int n=10;
int fact=1;
int i;
for(i=1;i<=n;i++){
fact=fact*i;
}
System.out.println(fact);
}
}

Write a program of Fibonacci numbers?

public class Main{
public static void main(String args[]){
int first=0;
int second=1;
int i;
System.out.println(first);
System.out.println(second);
for(i=1;i<=10;i++){
int third=first+second;
System.out.println(third);
first=second;
second=third;
}

}
}

Software Testing Question Bank for interview

Write a program of reverse?

public class Main{
public static void main(String args[]){
int n=56;
int r;
int x;
int y;
y=n%10;
x=n/10;
r=10*y+x;
System.out.println(r);

}
}

Write a program of swapping without third variables?

public class Main{
public static void main(String args[]){
int x=56;
int y=89;
x=x+y;
y=x-y;
x=x-y;
System.out.println(“Value of x=” +x);

System.out.println(“Value of Y=” +y);
}
}

Write a program of swapping with third variables?

public class Main{
public static void main(String args[]){
int n1=56;
int n2=89;
int n3;
n3=n1;
n1=n2;
n2=n3;

System.out.println(“Value of n1=” +n1);

System.out.println(“Value of n2=” +n2);
}
}

Please drop the comment regarding any query or for any suggestion/correction!

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Leave a Comment

2 × five =