Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 15 of 15

Thread: Help Me with my Program CompareTo!!!!

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs down Help Me with my Program CompareTo!!!!

    Hello guy
    guys i am working in aprogram and still i didn't did it right?

    the Qs. is to write a program that reads in 3 words from the user and then prints out the words in alphabetic order and.

    this is my codes:


    Please GUYS HELP ME!
    Last edited by WantHelp; July 4th, 2011 at 01:51 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Help Me with my Program CompareTo!!!!

    Can you show what your program prints out?

    Please wrap your code in code tags to preserve formatting. See: BB Code List - Java Forums

    if you don't know what the compareToIgnoreCase method is returning, use printlns to show you.
    For example:
    System.out.println("third.compareToIgnoreCase(firs t)=" + third.compareToIgnoreCase(first) +
    " third=" + third + ", first=" + first);

    What programming techniques do you know how to use now? Do you know about arrays?
    For this problem you would normally use arrays.

    Otherwise if you are supposed to use if() then
    can you describe the logic you are using to find the first, and then second and third?

  3. #3
    Junior Member
    Join Date
    Jul 2011
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help Me with my Program CompareTo!!!!

    I cant use array because i'm a beginner
    and when it print i don't get the in order
    for example if i wrote : cat cloud catch

    i get cat catch catch

  4. #4
    Junior Member
    Join Date
    Jul 2011
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help Me with my Program CompareTo!!!!

    and i'm using eclipse program

  5. #5
    Junior Member
    Join Date
    Jul 2011
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help Me with my Program CompareTo!!!!

    and the the anwser should be by if statement and compareToIgnoreCase method

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Help Me with my Program CompareTo!!!!

    Before you write any code, you need to design the logic for what the code is supposed to do, step by step.
    Have you done that? What are the steps you need to take to find the first string.

    i get cat catch catch
    Your code only changes the variable: two. The other two variables are never changed.

  7. #7
    Junior Member
    Join Date
    Jul 2011
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help Me with my Program CompareTo!!!!

    like i used the if statement for example for the first word:
    if(first.compareToIgnoreCase(second) < 0 && first.compareToIgnoreCase(third) > 0)  
     
    		{
    			two=first; 
    		}
    		if(first.compareToIgnoreCase(second) > 0 && first.compareToIgnoreCase(second) < 0)  
    		{
    		two=first;  
    		}




    PLEASE PLEASE HELP ME ON HOW TO FIX MY PROBLEM
    I DON'T WANT TO FAIL

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Help Me with my Program CompareTo!!!!

    Before you write any code, you need to design the logic for what the code is supposed to do, step by step.
    Have you done that? What are the steps you need to take to find the first string the lowest one.

  9. #9
    Junior Member
    Join Date
    Jul 2011
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help Me with my Program CompareTo!!!!

    i POSTED WHAT I DID IN MY FIRST POST UP
    !
    THAT WHAT I DID WITH MY PROGRAM ONLY

  10. #10
    Junior Member
    Join Date
    Jul 2011
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help Me with my Program CompareTo!!!!

    + WE NEVER DESIGN SOMETHING BEFORE WE WRITE A CODE
    WE ARE JUST BEGINNERS!
    FIRST CLASS OF JAVA!

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Help Me with my Program CompareTo!!!!

    Time to learn how to program. First you think about the problem, then you design a solution and then you write code.
    For example here is a design in pseudo code to find and save the smaller of two ints: one and two
    Compare the two ints
    if one is smaller than two
    smaller = one
    else
    smaller = two

    Now expand that to be for three items

  12. #12
    Junior Member
    Join Date
    Jul 2011
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help Me with my Program CompareTo!!!!

    so i do if first = one
    else
    first=two
    else=three??

  13. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Help Me with my Program CompareTo!!!!

    Sorry that makes no sense.
    Why are you testing for equality? To sort you need to know if one value is less than another.

    My algorithm started with:
    if one is smaller than two

    Your names are backwards for me. I think that you read in strings: one, two and three and then sort them so that first has the first in order, second has the second and third has the last(third).

    Try writing the logic for finding if one is the lowest of the three strings: one, two, three.

  14. #14
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Help Me with my Program CompareTo!!!!

    Quote Originally Posted by WantHelp View Post
    + WE NEVER DESIGN SOMETHING BEFORE WE WRITE A CODE
    WE ARE JUST BEGINNERS!
    FIRST CLASS OF JAVA!
    I suggest you take on board what Norm is saying if you wish to keep on everyone's good side
    Please don't delete your code from your original post. You have made it impossible to assist you.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  15. #15
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Help Me with my Program CompareTo!!!!

    Quote Originally Posted by WantHelp View Post
    + WE NEVER DESIGN SOMETHING BEFORE WE WRITE A CODE
    WE ARE JUST BEGINNERS!
    FIRST CLASS OF JAVA!
    You don't have to shout. Where's your code?

Similar Threads

  1. Replies: 3
    Last Post: June 1st, 2011, 12:47 AM
  2. Help with class program!!! STUCK! Program not doing what I Want!!!
    By sketch_flygirl in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 4th, 2011, 07:29 AM