Qantler Technologies – Interview Questions with Answers – Part – 3

This blog explains about Qantler Technologies – Interview Questions with Answers – Part – 3

We have already discussed some Qantler Technologies – Interview Questions with Answers – Part – 1 & 2 in the previous blogs . 

13 . Find biggest n value by one by one number . If q is get  then stop .

Given an array, find the largest element in it.

Input : arr[] = {10, 20, 4}

Output : 20

 

Input : arr[] = {20, 10, 20, 4, 100}

Output : 100

Method 1: Iterative Way

filter_none

edit

play_arrow

brightness_4

// Java Program to find maximum in arr[]

class Test

{

static int arr[] = {10, 324, 45, 90, 9808};

 

// Method to find maximum in arr[]

static int largest()

{

int i;

 

// Initialize maximum element

int max = arr[0];

 

// Traverse array elements from second and

// compare every element with current max

for (i = 1; i < arr.length; i++)

if (arr[i] > max)

max = arr[i];

 

return max;

}

 

// Driver method

public static void main(String[] args)

{

System.out.println(“Largest in given array is ” + largest());

}

}

Output:

Largest in given array is 9808

 

14 . Print the pyramid

PY

  • Number Pattern

filter_none

edit

play_arrow

brightness_4

import java.io.*;

 

// Java code to demonstrate number pattern

public class GeeksForGeeks

{

// Function to demonstrate printing pattern

public static void printNums(int n)

{

int i, j,num;

 

// outer loop to handle number of rows

//  n in this case

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

{

// initialising starting number

num=1;

 

//  inner loop to handle number of columns

//  values changing acc. to outer loop

for(j=0; j<=i; j++)

{

// printing num with a space

System.out.print(num+ ” “);

 

//incrementing value of num

num++;

}

 

// ending line after each row

System.out.println();

}

}

 

// Driver Function

public static void main(String args[])

{

int n = 5;

printNums(n);

}

}

 

15 . Get a value in a string and remove the special character .
// C# program to remove all the characters
// other then alphabets
using System;

class GFG {

// function to remove characters and
// print new string
static void removeSpecialCharacter(string s)
{
for (int i = 0; i < s.Length; i++)
{

// Finding the character whose
// ASCII value fall under this
// range
if (s[i] < ‘A’ || s[i] > ‘Z’ &&
s[i] < ‘a’ || s[i] > ‘z’)
{

// erase function to erase
// the character
s = s.Remove(i,1);
i–;
}
}

Console.Write(s);
}

// Driver code
public static void Main()
{
string s = “$Gee*k;s..fo, r’Ge^eks?”;
removeSpecialCharacter(s);
}
}

// This code is contributed by Sam007.

Output:
GeeksforGeeks

16 . Remove the duplicate number in an array .
// simple java program to remove
// duplicates

class Main
{
// Function to remove duplicate elements
// This function returns new size of modified
// array.
static int removeDuplicates(int arr[], int n)
{
// Return, if array is empty
// or contains a single element
if (n==0 || n==1)
return n;

int[] temp = new int[n];

// Start traversing elements
int j = 0;
for (int i=0; i<n-1; i++)
// If current element is not equal
// to next element then store that
// current element
if (arr[i] != arr[i+1])
temp[j++] = arr[i];

// Store the last element as whether
// it is unique or repeated, it hasn’t
// stored previously
temp[j++] = arr[n-1];

// Modify original array
for (int i=0; i<j; i++)
arr[i] = temp[i];

return j;
}

public static void main (String[] args)
{
int arr[] = {1, 2, 2, 3, 4, 4, 4, 5, 5};
int n = arr.length;

n = removeDuplicates(arr, n);

// Print updated array
for (int i=0; i<n; i++)
System.out.print(arr[i]+” “);
}
}

Output:
1 2 3 4 5

17 . Descending Order
//Java Example Program to print numbers in Descending order
/**
@author:candidjava.com
@description:Program to print numbers in Descending order
*/
public class Descending
{
public static void main(String args[])
{
int n=10;// take input as 10 to print descending order
System.out.println(“Descending order from 10”);
for(int i=n; i>=0; i–)// condition for print descending order
{
System.out.println(i);
}
}
}

output:

Descending order from 10:
10
9
8
7
6
5
4
3
2
1
0

18 . Get a string and get the display the vowels in the string

# Count vowels in a different way
# Using dictionary
def Check_Vow(string, vowels):

# casefold has been used to ignore cases
string = string.casefold()

# Forms a dictionary with key as a vowel
# and the value as 0
count = {}.fromkeys(vowels, 0)

# To count the vowels
for character in string:
if character in count:
count[character] += 1
return count

# Driver Code
vowels = ‘aeiou’
string = “Geeks for Geeks”
print (Check_Vow(string, vowels))

Output:
{‘u’: 0, ‘o’: 1, ‘e’: 4, ‘a’: 0, ‘i’: 0}

19 . Reverse a number
Reverse a Number using a while loop in Java
public class ReverseNumber {

public static void main(String[] args) {

int num = 1234, reversed = 0;

while(num != 0) {
int digit = num % 10;
reversed = reversed * 10 + digit;
num /= 10;
}

System.out.println(“Reversed Number: ” + reversed);
}
}
When you run the program, the output will be:
Reversed Number: 4321

REFERENCES :

 Qantler Technologies – Interview Questions with Answers – Part – 1 & 2  

https://payilagam.com/blogs/qantler-fresher-interview-questions-with-answers/

https://payilagam.com/blogs/qantler-technologies-fresher-interview-questions-with-answers/

https://www.geeksforgeeks.org/java-program-for-program-to-find-largest-element-in-an-array/

https://www.geeksforgeeks.org/programs-printing-pyramid-patterns-java/

https://www.geeksforgeeks.org/remove-characters-alphabets-string/

https://www.geeksforgeeks.org/remove-duplicates-sorted-array/

http://candidjava.com/java-example-program-to-print-numbers-in-descending-order/

https://www.geeksforgeeks.org/python-count-display-vowels-string/

https://www.programiz.com/java-programming/examples/reverse-number