Wednesday, December 21, 2011

Java program to print the initial letters of the words present in the string entered

/* This Java program accepts a String from the
 * user containing multiple words and then prints
 * a line containing all the initial letters of the
 * words present in the string separated by a dot.
 *
 * Sample Input: My name is Mayank
 * Sample Output: M.n.i.M.
 */

import java.util.*;
import java.lang.Object;
class initialLetter
{
    public static void main()
    {
        String s;
        System.out.println("Enter a String");
        Scanner sc=new Scanner(System.in);
        s=sc.nextLine();
        s=" "+s;
        int l=s.length();
        String ans="";
        char c='n';
        int i;
        for(i=0;i<l;i++)
        {
            c=s.charAt(i);
            if(c==' ')
            {
                ans=ans+s.charAt(i+1)+".";
            }
        }
        System.out.println("The final String: "+ans);
    }
}

//Author : Mayank Rajoria

1 comment:

  1. Las Vegas hotel and casino buffet: What to eat, sleep
    Wynn Resorts holds a monopoly on 광주 출장샵 the The Wynn 삼척 출장안마 Las Vegas is located in 동두천 출장샵 the heart of the 고양 출장안마 Las Vegas Strip, across the street from 광양 출장마사지 several

    ReplyDelete