Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By Fubarable

Thread: Pls help me with this problem

  1. #1
    kannan20 is offline Member
    Join Date
    Jan 2012
    Posts
    3
    Rep Power
    0

    Question Pls help me with this problem

    import java.io.*;
    import java.util.*;
    class alphabet
    {
    public static void main(String ar[])throws Exception
    {
    String[] ch={"a","b","c","d","e","f","g","h","i","j","k","l ","m","n","o","p","q","r","s","t","u","v","w","x", "y","z"};

    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Enter ur name: ");
    String[] name=new String[20];
    for(int a=0;a<6;a++)
    {

    name[a]=br.readLine();
    }
    for(int i=0;i<26;i++)
    {
    for(int a=0;a<6;a++)
    {
    if(ch[i]==name[a])
    System.out.print(ch[i]);
    }
    }
    }
    }




    Actually am trying to arrange the user input in a alphabetic order
    so i done this in c++ and got the results
    but in java the if(ch[i]==name[a]) is not comparing so anyone could help me with this code wat is the mistake and wat to do

    plz and thx in advance

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default Re: Pls help me with this problem

    Don't use == for comparing Strings or any other objects. Use the .equals(...) method.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    kannan20 is offline Member
    Join Date
    Jan 2012
    Posts
    3
    Rep Power
    0

    Default Re: Pls help me with this problem

    Darry but i dont know abt tat can u plz post the if condition again plz

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Pls help me with this problem

    Quote Originally Posted by kannan20 View Post
    Darry but i dont know abt tat can u plz post the if condition again plz
    Out of respect for us, please post only in standard English. It's hard enough to decipher questions here that you don't need to make it any harder.
    DarrylBurke likes this.

  5. #5
    kannan20 is offline Member
    Join Date
    Jan 2012
    Posts
    3
    Rep Power
    0

    Default Re: Pls help me with this problem

    oops sorry i didn't know that.... i am also weak in english.... anyway i got the program thank you friends :)

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default Re: Pls help me with this problem

    In general: on a forum, when you get an answer that you recognize as helpful, but can't understand fully, plug in a few keywords from that answer in your favorite search engine. Rare, highly specific questions are usually answered with full detail. But we do get tired of saying the same thing in full detail over and over again, when it's to be found in literally millions of web search results, the first few of which will suffice to provide adequate explanation.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Posting Permissions

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