Results 1 to 3 of 3
  1. #1
    Neeer is offline Member
    Join Date
    Mar 2011
    Posts
    6
    Rep Power
    0

    Post A java program to print short form of a name.

    import java.io.*;
    public class Netaji
    {
    public static void main()throws IOException
    {
    InputStreamReader reader=new InputStreamReader(System.in);
    BufferedReader input=new BufferedReader(reader);
    System.out.println("Enter your name please");
    String a=input.readLine();
    int count=a.length();
    int i=1,adprint;
    char pchar,hold;

    for(i=1;i<=count;i++)
    {
    hold=a.charAt(i);
    if(i==1)
    {
    pchar=a.charAt(0);
    System.out.print(pchar+".");
    }

    else if(hold==' ')
    {
    adprint=i+1;
    pchar=a.charAt(adprint);
    System.out.print(pchar+".");
    }
    }

    }

    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default

    Did you have a question, or is this just an exhibition of your l33t sk1llz?

    Recommended reading:
    Code Conventions for the Java(TM) Programming Language: Contents
    How To Ask Questions The Smart Way

    And use code tags to post code.

    db

  3. #3
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    Java Code:
    int i=1,adprint;
    for(i=1;i<=count;i++)

    you dont need to declare 'int i=1' before a for-loop. you can do that inside the loop e.g.
    Java Code:
    for (int i=1; i<=count; i++)

    and you should move this to the Java Tips section :P

Similar Threads

  1. short message service (SMS in java)
    By ashin in forum Advanced Java
    Replies: 4
    Last Post: 06-04-2011, 07:59 AM
  2. Replies: 3
    Last Post: 02-20-2011, 12:15 PM
  3. Very newbie trying to run form program
    By projecttoday in forum New To Java
    Replies: 2
    Last Post: 01-12-2011, 06:28 AM
  4. Replies: 1
    Last Post: 05-27-2010, 09:48 PM
  5. how to print out lines in a table- like form?
    By helloworld in forum New To Java
    Replies: 5
    Last Post: 02-10-2009, 09:31 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •