Write a java program to find username from a valid email string.

Write a program to read a valid email id and extract the username.

Note – username is the string appearing before @ symbol.

Input and Output Format:
Input consists of a string.
The output consists of string.
Refer sample output for formatting specifications.

Sample Input 1:
admin@xyz.com

Sample Output 1:
admin

Find username from a valid email string in java.

import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    String s1 = sc.nextLine();
    getvalues(s1);
  }

  public static void getvalues(String s1) {

    StringTokenizer st = new StringTokenizer(s1, "@");
    String s2 = st.nextToken();
    System.out.println(s2);

  }
}

Add a Comment

Your email address will not be published. Required fields are marked *

eighteen + 9 =