## CEO ITec Fresher Interview Questions & Answers

### a) Validate the email ids

// Java program to check if an email address

// is valid using Regex.

import java.util.regex.Matcher;

import java.util.regex.Pattern;

class Test

{

public static boolean isValid(String email)

{

String emailRegex = “^[a-zA-Z0-9_+&*-]+(?:\\.”+

“[a-zA-Z0-9_+&*-]+)*@” +

“(?:[a-zA-Z0-9-]+\\.)+[a-z” +

“A-Z]{2,7}\$”;

Pattern pat = Pattern.compile(emailRegex);

if (email == null)

return false;

return pat.matcher(email).matches();

}

/* driver function to check */

public static void main(String[] args)

{

String email = “contribute@geeksforgeeks.org”;

if (isValid(email))

System.out.print(“Yes”);

else

System.out.print(“No”);

}

### b) Sort the user name based on the string length .

 // Java program to sort an Array of  // Strings according to their lengths import java.util.*;   class solution {   // Function to print the sorted array of string // void printArraystring(string,int);   // Function to Sort the array of string // according to lengths. This function  // implements Insertion Sort.  static void sort(String []s, int n) {     for (int i=1 ;i= 0 && temp.length() < s[j].length())         {             s[j+1] = s[j];             j–;         }         s[j+1] = temp;     } }   // Function to print the sorted array of string static void printArraystring(String str[], int n) {     for (int i=0; i

### c) Sort the user name based on the alphabetical order

Java Program to Sort Names in an Alphabetical Order

The program output is also shown below.

1. import java.util.Scanner;

2. public class Alphabetical_Order

3. {

4.     public static void main(String[] args)

5.     {

6.         int n;

7.         String temp;

8.         Scanner s = new Scanner(System.in);

9.         System.out.print(“Enter number of names you want to enter:”);

10.         n = s.nextInt();

11.         String names[] = new String[n];

12.         Scanner s1 = new Scanner(System.in);

13.         System.out.println(“Enter all the names:”);

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

15.         {

16.             names[i] = s1.nextLine();

17.         }

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

19.         {

20.             for (int j = i + 1; j < n; j++)

21.             {

22.                 if (names[i].compareTo(names[j])>0)

23.                 {

24.                     temp = names[i];

25.                     names[i] = names[j];

26.                     names[j] = temp;

27.                 }

28.             }

29.         }

30.         System.out.print(“Names in Sorted Order:”);

31.         for (int i = 0; i < n – 1; i++)

32.         {

33.             System.out.print(names[i] + “,”);

34.         }

35.         System.out.print(names[n – 1]);

36.     }

37. }

### d) Count the domain , if you enter 2 email in gmail domain display count = 2

public class occurence_of_each_character

{

public static void main(String args[])

{

String str=”programming”;

int count=0;

for(char a=’A’;a<=’z’;a++)

{

count=0;

char k=a;

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

{

if(k==str.charAt(i))

{

count=count+1;

}

}

if(count>0)

{

System.out.println(a+”:”+count);

}

}

}

### References :

https://www.geeksforgeeks.org/sort-array-strings-according-string-lengths/