MVI Technologies Fresher Interview Questions

MVI Technologies Fresher Interview Questions 

This blog explains about MVI Technologies Fresher Interview Questions and is given below : 

 

1.In a given strg first letter should be in caps and last letter should be in small and find how many vowels present in the string.

// Java program to Convert characters 

// of a string to opposite case

class Test{

 

     // Method to convert characters 

     // of a string to opposite case

     static void convertOpposite(StringBuffer str)

     {

        int ln = str.length();

 

        // Conversion using predefined methods

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

        {

            Character c = str.charAt(i);

            if (Character.isLowerCase(c))

                str.replace(i, i+1, Character.toUpperCase(c)+””);

            else

                str.replace(i, i+1, Character.toLowerCase(c)+””);

 

        }

     }

 

     public static void main(String[] args) 

     {

         StringBuffer str = new StringBuffer(“GeEkSfOrGeEkS”);

         // Calling the Method

         convertOpposite(str);

 

         System.out.println(str);

        }

 }

// This code is contributed by Gaurav Miglani

Output:

gEeKsFoRgEeKs

 

2.Find the duplicate and the unique by using collection

// Java program to remove duplicates from ArrayList

 

import java.util.*;

 

public class GFG {

 

    // Function to remove duplicates from an ArrayList

    public static <T> ArrayList<T> removeDuplicates(ArrayList<T> list)

    {

 

        // Create a new ArrayList

        ArrayList<T> newList = new ArrayList<T>();

 

        // Traverse through the first list

        for (T element : list) {

 

            // If this element is not present in newList

            // then add it

            if (!newList.contains(element)) {

 

                newList.add(element);

            }

        }

 

        // return the new list

        return newList;

    }

 

    // Driver code

    public static void main(String args[])

    {

 

        // Get the ArrayList with duplicate values

        ArrayList<Integer>

            list = new ArrayList<>(

                Arrays

                    .asList(1, 10, 1, 2, 2, 3, 3, 10, 3, 4, 5, 5));

 

        // Print the Arraylist

        System.out.println(“ArrayList with duplicates: “

                           + list);

 

        // Remove duplicates

        ArrayList<Integer>

            newList = removeDuplicates(list);

 

        // Print the ArrayList with duplicates removed

        System.out.println(“ArrayList with duplicates removed: “

                           + newList);

    }

}

Output:

ArrayList with duplicates: [1, 10, 1, 2, 2, 3, 3, 10, 3, 4, 5, 5]

ArrayList with duplicates removed: [1, 10, 2, 3, 4, 5]

3.Find the prime numbers upto 20

class PrimeNumbers

{

   public static void main (String[] args)

   {

                    int i =0;

       int num =0;

       //Empty String

       String  primeNumbers = “”;

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

                {

                                      int counter=0;

            for(num =i; num>=1; num–)

           { 

            if(i%num==0) 

             {

                counter = counter + 1;

              } 

          }

           if (counter ==2)

           {

              //Appended the Prime number to the String

              primeNumbers = primeNumbers + i + ” “;

           }

             }

       System.out.println(“Prime numbers from 1 to 100 are :”);

       System.out.println(primeNumbers);   }}

Output:

Prime numbers from 1 to 100 are :

2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

4. Palindrome 1234321

  1. classPalindromeExample{  
  2. public static void main(String args[]){  
  3. int r,sum=0,temp;    
  4. int n=454;//It is the number variable to be checked for palindrome  
  5. temp=n;    
  6. while(n>0){    
  7. r=n%10;  //getting remainder  
  8. sum=(sum*10)+r;    
  9. n=n/10;    
  10. }    
  11. if(temp==sum)    
  12. out.println(“palindrome number “);    
  13. else
  14. out.println(“not palindrome”);    
  15. }  
  16. }  

Output:

palindrome  number

 

 

5. Using array find the 2nd largest number and 2nd smallest number in the given input

// Java program to find smallest and second smallest elements

import java.io.*;

 

class SecondSmallest

{

    /* Function to print first smallest and second smallest

      elements */

    static void print2Smallest(int arr[])

    {

        int first, second, arr_size = arr.length;

 

        /* There should be atleast two elements */

        if (arr_size < 2)

        {

            System.out.println(” Invalid Input “);

            return;

        }

 

        first = second = Integer.MAX_VALUE;

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

        {

            /* If current element is smaller than first

              then update both first and second */

            if (arr[i] < first)

            {

                second = first;

                first = arr[i];

            }

 

            /* If arr[i] is in between first and second

               then update second  */

            else if (arr[i] < second && arr[i] != first)

                second = arr[i];

        }

        if (second == Integer.MAX_VALUE)

            System.out.println(“There is no second” +

                               “smallest element”);

        else

            System.out.println(“The smallest element is ” +

                               first + ” and second Smallest” +

                               ” element is ” + second);

    }

 

    /* Driver program to test above functions */

    public static void main (String[] args)

    {

        int arr[] = {12, 13, 1, 10, 34, 1};

        print2Smallest(arr);

    }

}

/*This code is contributed by Devesh Agrawal*/

Output :

The smallest element is 1 and second Smallest element is 10

6. Write a java program to do the following

a) Read a file which contains the name of the students

Each line in the file is of the format Student name

Example Sam

                   Tim

                  Ram

                 Raghu

b) All the data from the file has to be loaded into one suitable data structure in java and duplicates have to be removed. Print the unique names from the file.

  1. #include <stdio.h>
  2. int main()
  3. {
  4. char name[50];
  5. int marks, i, num;
  6. printf(“Enter number of students: “);
  7. scanf(“%d”, &num);
  8. FILE *fptr;
  9. fptr = (fopen(“C:\\student.txt”, “w”));
  10. if(fptr == NULL)
  11. {
  12. printf(“Error!”);
  13. exit(1);
  14. }
  15. for(i = 0; i < num; ++i)
  16. {
  17. printf(“For student%d\nEnter name: “, i+1);
  18. scanf(“%s”, name);
  19. printf(“Enter marks: “);
  20. scanf(“%d”, &marks);
  21.   fprintf(fptr,”\nName: %s \nMarks=%d \n”, name, marks);
  22. }
  23. fclose(fptr);
  24. return 0;
  25. }

 

REFERENCES : 

https://www.geeksforgeeks.org/convert-alternate-characters-string-upper-case/

https://beginnersbook.com/2014/01/java-program-to-display-prime-numbers/

https://www.javatpoint.com/palindrome-program-in-java

https://www.geeksforgeeks.org/to-find-smallest-and-second-smallest-element-in-an-array/

https://www.programiz.com/c-programming/c-file-examples

https://www.programiz.com/c-programming/c-file-examples