Java games with lists are very popular. This makes sense, since they are all so simple and interesting. Join in the fun! In this task, we create a list of strings. Then we add 10 strings from the keyboard. The most interesting part is that we'll determine whether the shortest string or the longest string is encountered first in the list. If more than one string is shortest or longest, we'll consider the very first one we encounter.
Shortest or longest
- 10
Locked
Comments (24)
- Popular
- New
- Old
You must be signed in to leave a comment
Usman Full Stack Developer at QA
5 July 2021, 15:08
got this on my first attempt and im so proud :D took me nearly half an hour tho, but it was a really good challange.
was able to break the problem down step by step.
Really enjoyed it.
+3
Daisy
2 June 2021, 08:40
HINT: you can use this loop to find the first shortest/longest string
int i=0;
while(strings.get(i).length()!=shortest&&strings.get(i).length()!=longest){
i++;
}
System.out.println(strings.get(i));
0
ImDevin
20 April 2021, 16:45
Did it another way, but in the end you have to compare lengths to pass. Don't forget to use break;
0
ImDevin
20 April 2021, 14:45
only took 14 tries - awesome :/ the crappy thing is I don't like the solution. Gonna try to solve it another way!
0
queldorm
8 November 2020, 15:05
this one was ridiculous. I correctly wrote the program in serval different ways. The program compiled and ran with no errors and met the requirements of the task, yet some how the task checker failed me because I didn't use the exact implementation It was looking for.
0
Nutty Coder
22 October 2020, 14:43
This task was a good challenge.
0
George
5 September 2020, 21:18
got this working in 1 try but still don't like my code much. Had to store the strings and array index in separate variables then compare them. Any suggestion for a tidier code?
0
Switch/Cypher
12 September 2020, 16:52
What you describe sounds like exactly what I did. Work out the shortest, work out the longest, get the index of both, compare.
+3
Angel Stefan
16 November 2021, 15:22
Nice pseudocode "Work out the shortest, work out the longest, get the index of both, compare." Job done! :)
0
Petros
21 July 2020, 18:52
I had to use the index.of method for arrays to get this correct.
+2
Edddieg
21 June 2020, 16:45
can someone please explain this question to me thank you
0
Moamal
14 July 2020, 09:58
In this task , you are given many words and you have to determinate from the list whether the smallest or the biggest word came first and display it on the screen
for example the words ( ground , in , on , yellow , grandmother , yellow )
the biggest : grandmother
the smallest : in ,on
since the smallest came first you should display it (only one word 'in' )
+2
Katarina
7 February 2020, 11:50
When you do this task after all previous in this lesson it is quite easy :)
+1