Friday, October 21, 2011

Shorten Name

import java.io.*;
class ShortName
{
String help="fast";
protected static void main()throws IOException
{
    BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Enter your name: ");
    String s=in.readLine();
    char ch; short c=0,d=0,e=0;
    do
    {
        ch=s.charAt(d);
        if(ch==' ')
        c++;
        d++;
    }while(d<s.length());
    String w[]=new String[c+1];
    for(d=0;d<=c;d++)
    w[d]="";
    for(d=0;d<s.length();d++)
    {
        ch=s.charAt(d);
        if(ch==' ')
        {
            e++;
            continue;
        }
        w[e]+=ch;
    }
    for(d=0;d<=c;d++)
    {
        if(d==c)
        System.out.print(w[d]);
        else
        System.out.print(w[d].charAt(0)+". ");
    }
}
}

No comments:

Post a Comment