Qantler Technologies Java interview questions with answers – PART 1

In this post, we are going to discuss Quantler Technologies Java interview programming questions with their sample codes. The interview was based on checking the programming skills and thinking ability of the candidates. Let us discuss the programs briefly;

1)Write a java program to get a number from the user and check whether it is odd or even:

SAMPLE CODE-

import java.util.Scanner;
public class Odd_Even
{
public static void main(String[] args)
{
int n;
Scanner s = new Scanner(System.in);
System.out.print(“Enter the number you want to check:”);
n = s.nextInt();
if(n % 2 == 0)
{
System.out.println(“The given number “+n+” is Even “);
}
else
{
System.out.println(“The given number “+n+” is Odd “);
}
}
}

SAMPLE OUTPUT-

Enter the number you want to check:15
The given number 15 is Odd

2)Write a java program to reverse a number:

SAMPLE CODE-

import java.io.*;
import java.lang.*;

class Reverse
{
public static void main(String args[]) throws IOException
{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

System.out.println(“Enter Number: “);
int num=Integer.parseInt(br.readLine());

int remainder, result=0;
while(num>0)
{
remainder = num%10;
result = result * 10 + remainder;
num = num/10;
}
System.out.println(“Reverse number is : “+result);
}
}

SAMPLE OUTPUT-

Enter Number:
1234
Reverse number is : 4321

3)Write a java program to add all digits in a number, ex. 542 (5+4+2=11)

SAMPLE CODE-

class GFG {

/* Function to get sum of digits */
static int getSum(int n)
{
int sum = 0;

while (n != 0)
{
sum = sum + n % 10;
n = n/10;
}

return sum;
}

// Driver program
public static void main(String[] args)
{
int n = 542;

System.out.println(getSum(n));
}
}

SAMPLE OUTPUT-

11

4)Write a java program to find factorial of a number using recursion:

SAMPLE CODE-

import java.util.Scanner;
public class Factorial
{
public static void main(String[] args)
{
int n, mul;
Scanner s = new Scanner(System.in);
System.out.print(“Enter any integer:”);
n = s.nextInt();
Factorial obj = new Factorial();
mul = obj.fact(n);
System.out.println(“Factorial of “+n+” :”+mul);
}
int fact(int x)
{
if(x > 1)
{
return(x * fact(x – 1));
}
return 1;
}
}

SAMPLE OUTPUT-

Enter any integer:8
Factorial of 8 :40320

To be continued…

References:

https://www.sanfoundry.com/java-program-check-given-integer-odd-even/

https://www.programming9.com/programs/java/31-java-program-to-reverse-a-number

https://www.geeksforgeeks.org/program-for-sum-the-digits-of-a-given-number/

https://www.sanfoundry.com/java-program-find-factorial-value-with-using-recursion/