Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Help with programming homework?

I had 3 labs for Programming and this last one I just can't get here's the guidelines:

Create a string ArrayList. Fill it with 10 strings using the set method. Use a for loop to put the arraylist in alphabetical order. (clue use compareTo) You will also need to determine the longest and shortest string. at the end print out the newly ordered list as well as the longest and shortest string.

Any help would be greatly appreciated. (Do not have to do the problem for me just give me a basis where to start) I know how to create the arraylist but the looping is where I have trouble.

1 Answer

Relevance
  • cpcii
    Lv 7
    5 years ago

    In what language? A For loops is pretty simple, basic is:

    for loopcounter = 1 to 10

    ... Do something in the loop

    ... arraylist[loopcouter]="set to something"

    end loopcoutner //this will go back to the next iteration until loopcounter =10

    then after that, you have to do a sort of some type, depending upon your language this might be included, if not write your own sort.

    then do another loop to go through all 10 in the list and see which is the shortest

    longeststring = 0

    shorteststring = 0

    for newloop = 1 to 10

    .. if arraylist[newloop].length > longeststring set longeststring = newloop else skip

    ... if arraylist[newloop].length < shorteststring set shorteststring = newloop else skip

    end for

    print arraylist[longeststring]

    print arraylist[shorteststring]

Still have questions? Get your answers by asking now.