Results 1 to 2 of 2
  1. #1
    ScarabVenom is offline Member
    Join Date
    Oct 2012
    Rep Power

    Exclamation JAVA assignment help


    I'm new to Java and I have to write a program that sorts 3 names alphabetically. I didn't learn Arrays yet so, I can't use it. I wrote the program already using if-else-if statements and it's working but, in order to do this I had to basically code every single possibility. The professor said that there's a way in which you compare two of the names, find the smallest and keep it at the bottom and then compare the other two. She refused to say more and I really can't find a way. I hope someone can help.
    I know that this is not a "do homework for you" forum. I already have the program compiling and working and I can provide my code. But, I just don't understand how comparing 2 names can show me the smallest one. For example, if I compared the first 2 names and found the smallest of them....well, the third one can turn out to be the smallest.
    Last edited by ScarabVenom; 10-15-2012 at 05:39 AM.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Rep Power

    Default Re: JAVA assignment help

    Quote Originally Posted by ScarabVenom View Post
    find the smallest and keep it at the bottom
    At the bottom of what?

    Consider doing this with 3 ints (8,2,5). What you can do is compare the first value to the second and the first value to the third to see if it is smallest (or largest). If it is then you need to compare the other two values to know what order they fall in using a nested if statement.

    So it would something like:
    if (8 > 2 && 8 > 5)
    if (2 > 5)
    the order is 8 2 5 (or 5 2 8 depending on ascending or descending)
    the order is 8 5 2 (or 2 5 8)
    else if.... (a)


    (a) We now know the first value is not the largest so all you need do is compare the second and third value
    (b) We now know the last value must be largest.

    In both (a) and (b) you will still need to perform the comparison between the other 2 values.

Similar Threads

  1. Java Assignment
    By lance215 in forum New To Java
    Replies: 1
    Last Post: 06-15-2012, 12:11 AM
  2. Java Assignment Help
    By nve5009 in forum New To Java
    Replies: 4
    Last Post: 04-27-2011, 06:36 AM
  3. Need Help with Java Assignment
    By smurf67 in forum New To Java
    Replies: 4
    Last Post: 03-26-2011, 10:25 AM
  4. My java assignment -- please help me !
    By java_beginner1 in forum New To Java
    Replies: 11
    Last Post: 05-20-2010, 04:00 PM
  5. Java assignment
    By xtianah77 in forum New To Java
    Replies: 1
    Last Post: 02-17-2008, 11:54 PM

Posting Permissions

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