Search Tutorials

Tuesday, 23 April 2013

Java code to print the initials of a Name

Java program to print the initials of a name.

class Initials
 static String n;
 static int l;
 public static void main(String args[]) throws IOException
 Initials call = new Initials();
 BufferedReader br = new BufferedReader(new
 System.out.print("Enter a Name : ");
 n = br.readLine();
 l = n.length();
 public void init()
 int c=0;
 char b=0,d=0;
 String e = "";
 for(int i=0;i<l;i++)
  if(n.charAt(i)==' ')
   b = n.charAt(i+1);
   d = n.charAt(i+1);
   e = n.substring(i+1);
 char f = n.charAt(0);
 System.out.println(f +"." +b +"." +e);
 System.out.println(f +"." +b +"." +d +".");
 System.out.println(e +" " +f +"." +b +".");


1. Start

2. Accept a name from the user.

3. In a two word name, break the name from the first occurring blank-space.

4. In a three word name, break the name from the second occurring blank-space.

5. Print the first letter of each word and the surname.

6. End


Java code to print the initials of a Name

Enter a Name : Mayank K Rastogi



Rastogi M.K.

Related Programs:-

Convert a number into words

Reverse a word or sentence ending with '.' using recursion

Convert Decimal to Octal

Convert Decimal to Binary

Print the Factorial of a number using recursion

1 comment:

  1. Thanks for sharing a useful information with us. If someone wants to know about Safety Softwares and Occupational health and Safety Software I think this is the right place for you.


Back to Top