Go to Top

Monday, 3 October 2011

Utilities 12 : Name initials

This program will help you to print the initials of a name taken as input from the user.

Java Program :

import java.io.*;
class name_initials
{
 static void main()throws IOException
 {
     BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
     int i,d=0,space=0;
     char k;
     String a;
     System.out.print("Enter the name : ");
     a=br.readLine();
     System.out.print("\nName initials : ");
     for(i=0;i<a.length();i++)
     {
         k=a.charAt(i);
         if(k==' ')
         {
             space=i+1;
             System.out.print(a.charAt(d)+".");
             d=i+1;
            }
        }
            for(i=space;i<a.length();i++)
            {
                k=a.charAt(i);
                System.out.print(k);
            }
            System.out.print("\n");
            System.out.println("\nThank you for using this short program");
       
    }
}
               
       
             

2 comments:

  1. EVEN THOUGH I MODIFIED THE PROGRAM USING SCANNER CLASS;
    THANKS A LOT !!!

    ReplyDelete

ShareThis