String + Compare // Might be too easy for ya
I'm a new student trying to learn java and i have been stuck on this question in the practice sheet and i cannot do it. So please help me out here.
Instructions:
- Let the user Input 3 Strings "Bait, Car, Animal"
- Then you have to sort this in alphabatic order and print it
Animal, Car, Bait.
I tried and i looked up ways and i found very advanced coding, like import.util.List etc :P
What i learned so far is using
while - for - do loops
if - else if statments
and compareTo < 0
if that might help, please help me learn this with my simple knowledge, i would be so greateful to you
Re: String + Compare // Might be too easy for ya
The import isn't that advanced, it's just saying that you want to use the Java API's List interface. However, I doubt that's what you want because that's probably not what your professor is looking for (besides, who likes to use the standard API when you can create the methods yourself?).
All you need is a good sorting algorithm. The simplest to implement are selection sort and insertion sort. Selection sort's slightly easier to implement, but insertion sort is "more efficient" when the list is more sorted.