Programming Blog

This blog is about technical and programming questions and there solutions. I also cover programs that were asked in various interviews, it will help you to crack the coding round of various interviews

Wednesday, 17 August 2016

Java program to print initials of Name...

                      This Program Prints Name Initials.

For ex . Input => mohammad xyzabc alam
            Output =>M.X. ALAM
----------------------------------------------------PROGRAM------------------------------------

import java.util.Scanner;
public class LaastNmae {
      public static void main(String []argv)
     {
         int d=0,space=0;
         String a;
         Scanner br=new Scanner(System.in);
         System.out.println("Enter the name  =>");
         a=br.nextLine();
         System.out.print("\nName initials : ");
         for( int i=0;i<a.length();i++)
         {
            
             if(a.charAt(i)==' ')
             {
                 space=i+1;
                 System.out.print(a.toUpperCase().charAt(d)+".");
                 d=i+1;
                }
            }
                for( int i=space;i<a.length();i++)
                {
                    System.out.print(a.toUpperCase().charAt(i));
                   
                }
              
             br.close();  
        }

}

No comments:

Post a Comment