In what way is 'Watermellon', 'Bob', 'Cherry', 'Apple' a sorted list of words? It is not alphabetical by start letter, it is not by string size either, yet it is used as an example of correct output for the last task?
I believe the example output is incorrect - it should be:
Apple
22
Bob
3
Cherry
1
0
Watermelon
This output passed validation for me.
The words are being sorted with the String.compareTo method, which compares the strings based on the Unicode values of each of their characters. You can ctrl + left click on the methods in intelliJ to navigate to the method declaration and read more about its implementation.
Anonymous #10853261Level 1, Queens: git commit -m 'get the money', United States
6 December 2021
Note that on the task "List of number arrays", you need to add "import java.util.Arrays;" in order for the program to compile correctly because of the existing code in the printList method.
task0919 (Dividing by zero) caveat: requirement 6 (The program should display the stack trace of the caught exception.) can only be met by calling a certain system-provided function for printing the stack trace or - maybe - by exactly imitating its output format.
You dont want to do that. You want to compare numbers to numbers, and strings as string.compareTo(string) because that is lexiconical (String(22) is < String(5))
At least one of these tasks requires knowledge of certain things (e.g. StringBuffer) we haven't been taught yet. What's the reason behind that?
Justin SmithLevel 41, Greenfield, USA, United States
21 July 2021
Many tasks, especially the hard ones, will do this. You may have to google how to do something. This is encouraged. Professional programmers don't memorize everything, and they, too, have to look things up sometimes. It's a practice you should get used to.
A scary fairy tale task uses this version:
Wolf ate granmother, then he ate red riding hood and was killed by a woodcutter.
How to work with SimpleDateFormat - read this article
GO TO FULL VERSION