RGS Construction Fresher Interview Questions – Part – I
This blog explains about RGS Construction Fresher Interview Questions – Part – I in detail. Some of them are explained below :
______________________________________________________________________
1) To find whether vowel present in an array and print the vowel and it’s count
// Java program to count vowels in a string
public class GFG {
// Function to check the Vowel
static boolean isVowel(char ch)
{
ch = Character.toUpperCase(ch);
return (ch==’A’ || ch==’E’ || ch==’I’ ||
ch==’O’ || ch==’U’);
}
// Returns count of vowels in str
static int countVowels(String str)
{
int count = 0;
for (int i = 0; i < str.length(); i++)
if (isVowel(str.charAt(i))) // Check for vowel
++count;
return count;
}
// Driver code
public static void main(String args[])
{
//string object
String str = “abc de”;
// Total numbers of Vowel
System.out.println(countVowels(str));
}
}
________________________________________________________
2) Perfect number
1. import java.util.Scanner;
2. public class Perfect
3. {
4. public static void main(String[] args)
5. {
6. int n, sum = 0;
7. Scanner s = new Scanner(System.in);
8. System.out.print(“Enter any integer you want to check:”);
9. n = s.nextInt();
10. for(int i = 1; i < n; i++)
11. {
12. if(n % i == 0)
13. {
14. sum = sum + i;
15. }
16. }
17. if(sum == n)
18. {
19. System.out.println(“Given number is Perfect”);
20. }
21. else
22. {
23. System.out.println(“Given number is not Perfect”);
24. }
25. }
26. int divisor(int x)
27. {
28. return x;
29. }
30. }
Output:
$ javac Perfect.java
$ java Perfect
Enter any integer you want to check:6
Given number is Perfect
_______________________________________________________________________
3)Get the input from the user and find whether the given array is in sorted order
1. import java.util.Scanner;
2. public class Ascending _Order
3. {
4. public static void main(String[] args)
5. {
6. int n, temp;
7. Scanner s = new Scanner(System.in);
8. System.out.print(“Enter no. of elements you want in array:”);
9. n = s.nextInt();
10. int a[] = new int[n];
11. System.out.println(“Enter all the elements:”);
12. for (int i = 0; i < n; i++)
13. {
14. a[i] = s.nextInt();
15. }
16. for (int i = 0; i < n; i++)
17. {
18. for (int j = i + 1; j < n; j++)
19. {
20. if (a[i] > a[j])
21. {
22. temp = a[i];
23. a[i] = a[j];
24. a[j] = temp;
25. }
26. }
27. }
28. System.out.print(“Ascending Order:”);
29. for (int i = 0; i < n – 1; i++)
30. {
31. System.out.print(a[i] + “,”);
32. }
33. System.out.print(a[n – 1]);
34. }
35. }
Output:
$ javac Ascending _Order.java
$ java Ascending _Order
Enter no. of elements you want in array:5
Enter all the elements:
4
3
2
6
1
Ascending Order:1,2,3,4,6
_______________________________________________________________________
4) Program to find the maximum values which is repeated in an array
class MinMaxExample {
public static void main(String args[]){
int array[] = new int[]{10, 11, 88, 2, 12, 120};
// Calling getMax() method for getting max value
int max = getMax(array);
System.out.println(“Maximum Value is: “+max);
// Calling getMin() method for getting min value
int min = getMin(array);
System.out.println(“Minimum Value is: “+min);
}
// Method for getting the maximum value
public static int getMax(int[] inputArray){
int maxValue = inputArray[0];
for(int i=1;i < inputArray.length;i++){
if(inputArray[i] > maxValue){
maxValue = inputArray[i];
}
}
return maxValue;
}
// Method for getting the minimum value
public static int getMin(int[] inputArray){
int minValue = inputArray[0];
for(int i=1;i<inputArray.length;i++){
if(inputArray[i] < minValue){
minValue = inputArray[i];
}
}
return minValue;
}
}
Output:
Maximum Value is: 120
Minimum Value is: 2
_______________________________________________________________________
REFERENCES :
https://www.geeksforgeeks.org/program-count-vowels-string-iterative-recursive/
https://www.sanfoundry.com/java-program-check-given-number-perfect-number/
https://www.sanfoundry.com/java-program-sort-array-ascending-order/
https://beginnersbook.com/2014/07/java-finding-minimum-and-maximum-values-in-an-array/