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
- classPalindromeExample{
- public static void main(String args[]){
- int r,sum=0,temp;
- int n=454;//It is the number variable to be checked for palindrome
- temp=n;
- while(n>0){
- r=n%10; //getting remainder
- sum=(sum*10)+r;
- n=n/10;
- }
- if(temp==sum)
- out.println(“palindrome number “);
- else
- out.println(“not palindrome”);
- }
-
}
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.
- #include <stdio.h>
- int main()
- {
- char name[50];
- int marks, i, num;
- printf(“Enter number of students: “);
- scanf(“%d”, &num);
- FILE *fptr;
- fptr = (fopen(“C:\\student.txt”, “w”));
- if(fptr == NULL)
- {
- printf(“Error!”);
- exit(1);
- }
- for(i = 0; i < num; ++i)
- {
- printf(“For student%d\nEnter name: “, i+1);
- scanf(“%s”, name);
- printf(“Enter marks: “);
- scanf(“%d”, &marks);
- fprintf(fptr,”\nName: %s \nMarks=%d \n”, name, marks);
- }
- fclose(fptr);
- return 0;
- }
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