Qantler Technologies –  Fresher Interview Questions – Part – III

This blog explains about Qantler Technologies –  Fresher Interview Questions – Part – III . Some of the questions are discussed below . They are :

We have already discussed about few questions in the previous blogs – Qantler Technologies –  Fresher Interview Questions – Part – I & II 

 REFERENCES :

https://payilagam.com/blogs/qantler-technologies-fresher-interview-questions-part-i/

https://payilagam.com/blogs/qantler-technologies-fresher-interview-questions-part-ii/

https://payilagam.com/blogs/qantler-technologies-fresher-interview-questions-part-ii/

 1. Write a program to Print  star in triangle format ? 

Print star pattern in java

class StarTriangle

{

public static void main(String[] args)

{int i,j,k;

for(i=1; i<=5; i++)

{

for(j=4; j>=i; j–)

{

System.out.print(” “);

}

for(k=1; k<=(2*i-1); k++){

System.out.print(“*”);

}

System.out.println(“”);

}

}

}

Output

          *

        *  *

       *  *  *

     *  *  *  *

   *   *  *  *  *

______________________________________________________________________________

2. Find  duplicate elements In Array

// C++ program to find

// duplicates in the given array

#include <bits/stdc++.h>

using namespace std;

 

// function to find and print duplicates

void printDuplicates(int arr[], int n)

{

    // unordered_map to store frequencies

    unordered_map<int, int> freq;

    for (int i=0; i<n; i++)

        freq[arr[i]]++;

 

    bool dup = false;

    unordered_map<int, int>:: iterator itr;

    for (itr=freq.begin(); itr!=freq.end(); itr++)

    {

        // if frequency is more than 1

        // print the element

        if (itr->second > 1)

        {

            cout << itr->first << ” “;

            dup = true;

        }

    }

 

    // no duplicates present

    if (dup == false)

        cout << “-1”;

}

 

// Driver program to test above

int main()

{

    int arr[] = {12, 11, 40, 12, 5, 6, 5, 12, 11};

    int n = sizeof(arr) / sizeof(arr[0]);

    printDuplicates(arr, n);

    return 0;

}

Output:

12 11 5

___________________________________________________________________

3. Write a program to Reverse a string ? 

// Java program to ReverseString using ByteArray.

import java.lang.*;

import java.io.*;

import java.util.*;

 

// Class of ReverseString

class ReverseString

{

    public static void main(String[] args)

    {

        String input = “Payilagam”;

 

        // getBytes() method to convert string 

        // into bytes[].

        byte [] strAsByteArray = input.getBytes();

 

        byte [] result = 

                   new byte [strAsByteArray.length];

 

        // Store result in reverse order into the

        // result byte[]

        for (int i = 0; i<strAsByteArray.length; i++)

            result[i] = 

             strAsByteArray[strAsByteArray.length-i-1];

 

        System.out.println(new String(result));

    }

}

Run on IDE

Output:

“magaliyaP”

______________________________________________________________________________

4 . Write a program to print even numbers in an array ?

Print even numbers in  array   

main()

 

02 {

 

03  

 

04 int a[100], n = 0, i = 0; //init

 

05 printf(“Enter the number of elements\n”);

 

06 scanf(“%d”, &n);

 

07 for(i=0; i<n; i++) //removed the ; from the end and i is initialised with 0 not a

 

08  

 

09 {

 

10 scanf(“%d”, &a[i]);

 

11 }

 

12  

 

13 for(i=0; i<n; i++) //same remark as pevious for

 

14  

 

15 {

 

16 if(a[i]%2==0) //test if even

 

17  if (a[i] < 0) //if is even test if negative

 

18 {

 

19 printf(“The negative even number %d \n”, a[i]);

 

20 }

 

21  

 

22 }

 

23  

 

24 }

__________________________________________________________________________________