String handling - email id generation


// String handling

/*
Write a java program that reads a string from inputs containing first name, last name and computes an e-mail address with first 3 letters of the first name, first 4 letters of last name, '.' separator and domain. Display the outputs by invoking objects.                                            
*/

import java.util.*;

class email
{
     String fn, ln;
     Scanner s = new Scanner(System.in);
    
     public void fnread()
     {
          System.out.print("Enter first name : ");
          fn = s.next();
          System.out.print("Enter last name : ");
          ln = s.next();
     }
    
     public void fnGenerate()
     {
          if(fn.length()<3 || ln.length()<4)
              System.out.print("invalid input. Email id cannot be generated.");
          else
          {
              String emailid = fn.substring(0,3)+"."+ln.substring(0,4)+"@gmail.com";
              System.out.println("Email id : "+emailid);
          }
     }
}
class SH1
{
     public static void main(String as[])
     {
          email eid = new email();
          eid.fnread();
          eid.fnGenerate();
     }
}
         
    

1 comment:

Don't be a silent reader...
Leave your comments...

Anu