Contents of input file:
Okinawa Denver RioDeJaneiro Washington Auckland Kalamazoo Norfolk
Console output:
Washington Norfolk Kalamazoo Okinawa Auckland Denver RioDeJaneiro
In the main method, read the name of a file that contains words separated by spaces from the console.
In the getLine method, use StringBuilder to order all the words as follows: the last letter of a word must match the first letter of the next word (ignore case).
Each word should be used once.
The getLine method can return any variant.
Separate words with a space.
Display the resulting string on the screen.
Example input file:
OkinawaWashingtonAucklandKalamazooNorfolk
Result:
WashingtonNorfolkKalamazooOkinawaAuckland
Requirements:
The main method must read the filename from the keyboard.
There should not be static fields in the Solution class.
The getLine method must use StringBuilder.
The getLine method must return an empty string (an empty StringBuilder) if it is not passed arguments (words).
The getLine method must not change the arguments (words).
All words passed to the getLine method must be included in the resulting string, if possible.
The screen output must match the task conditions.
....
Okinawa Denver RioDeJaneiro Washington Auckland Kalamazoo Norfolk
Unfortunately I do not know Codegym's test cases but if they use something like 4chan it will become @chan while the comparison word is lowercased using a String method that leaves the @ untouched.
So I'd rework lines 66 - 69 and use either String.toLowerCase() or the static counterpart from the Character class head = Character.toLowerCase(head) or, if you stay with strings, use String.equalsIgnoreCase()
When I make this change, then my testcase