I am new at programming and I have never done Java before. I am in my first Java class and we are asked to complete the following question...Complete the method printLargestAnimal below.

Consider the three Strings "dog", "cat", and "monkey". In lexicographical order, "monkey" is the largest of the three, since "monkey" appears the latest in an English dictionary. Write a method called printLargestAnimal, which takes three animal names as Strings and prints the largest one by size of name according to the compareTo method from String class. Thus, if the method were passed "dog", "cat", and "monkey", it would print "monkey".

I am totally lost and have no idea how to use the compareTo method. I don't understand how to get it to print out the animal name. Thank you

11 Years
Discussion Span
Last Post by crackers8838

Have you looked through the Java API?
If you still can't get it to work, post what you have (remember to wrap it in [.code] [/code] tags) and we'll have a look at what may be missing.
You will also need to read this thread.


Thanks for the help. I got it working. I just had some stuff mixed around. Thanks again.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.