Ducima Analytics Java Interview Questions with Answers

We are discussing about various companies’ interview questions with answers in our previous posts. In this post, we are going to discuss about Ducima Analytics Java Interview Questions with Answers. The interview questions are based on checking the programming skill of the candidates. Let us discuss the questions briefly;

1. Print the duplicate charaters in the string:

String str = “Hello World”;

CODE:

public class DuplStr {
public static void main(String argu[]) {

String str = “Hello World”;
int cnt = 0;
char[] inp = str.toCharArray();
System.out.println(“Duplicate Characters are:”);
for (int i = 0; i < str.length(); i++) {
for (int j = i + 1; j < str.length(); j++) {
if (inp[i] == inp[j]) {
System.out.println(inp[j]);
cnt++;
break;
}
}
}
}
}

OUTPUT:

Duplicate Characters are: l o

2.Print the sum of the digit:

int a = 3489;

CODE:

// Java program to compute
// sum of digits in number.
import java.io.*;

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 = 3489;

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

OUTPUT:

6

3. Write a program for Method overriding.

ANSWER:

Method overriding feature in OOPS allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its superclasses or parent classes.

SAMPLE CODE:

class MethodOverridingExample{
public void add(int num1,int num2){
int result1=num1+num2;
System.out.println(“Result of parent class method is “+result1);
}
}

class OverriddenMethod{
public void add(int num1,int num2){
int result2=num1-num2;
System.out.println(“Result of overridden method is “+result2);
}
}

class MainMethodOverriding{
public static void main(String[] args){
MethodOverridingExample obj1= new MethodOverridingExample();
obj1.add(7,5);
OverriddenMethod obj2=new OverriddenMethod();
obj2.add(7,5);
}
}

SAMPLE OUTPUT:

Output is:
Result of parent class method is 12
Result of overridden method is 2

4. Print First Two Max Numbers in an array.

int[]arr = {5,43,78,2,45,99,23};

CODE:

// Java code to find largest three elements
// in an array

class PrintLargest
{
/* Function to print three largest elements */
static void print2largest(int arr[], int arr_size)
{
int i, first, second, third;

/* There should be atleast two elements */
if (arr_size < 3)
{
System.out.print(” Invalid Input “);
return;
}

third = first = second = Integer.MIN_VALUE;
for (i = 0; i < arr_size ; i ++)
{
/* If current element is smaller than
first*/
if (arr[i] > first)
{
third = second;
second = first;
first = arr[i];
}

/* If arr[i] is in between first and
second then update second */
else if (arr[i] > second)
{
third = second;
second = arr[i];
}

else if (arr[i] > third)
third = arr[i];
}

System.out.println(“First Two Max Numbers are ” +
first + ” ” + second + ” ” + third);
}

/* Driver program to test above function*/
public static void main (String[] args)
{
int arr[] = {5,43,78,2,45,99,23};
int n = arr.length;
print2largest(arr, n);
}
}

OUTPUT:

First Two Max Numbers are 99 78

References:
https://www.w3schools.in/java-program/java-program-find-duplicate-characters-string/

http://www.java2novice.com/java-interview-programs/duplicate-string-character-count/

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

https://www.sanfoundry.com/java-program-compute-sum-digits-number/

https://www.java-programs.thiyagaraaj.com/method_overriding_java_example_program.html

https://www.geeksforgeeks.org/overriding-in-java/

https://www.geeksforgeeks.org/find-the-largest-three-elements-in-an-array/

https://codingpuzzles.com/write-a-java-program-to-find-top-two-maximum-numbers-in-the-given-array-3fc08e6afd4e