Shortest or longest

  • 10
  • Locked
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.
You can't complete this task, because you're not signed in.
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.
Level 8 , San Jose
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));
Level 15 , Old Town, United States
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;
Level 15 , Old Town, United States
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!
Level 11 , East coast, United States
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.
Nutty Coder
Level 8 , United States
22 October 2020, 14:43
This task was a good challenge.
Level 15 , United Kingdom
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?
Level 25 , Bexleyheath, United Kingdom
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.
Angel Stefan
Level 23 , Sibiu, Romania
16 November 2021, 15:22
Nice pseudocode "Work out the shortest, work out the longest, get the index of both, compare." Job done! :)
Level 23 , Columbia, United States
21 July 2020, 18:52
I had to use the index.of method for arrays to get this correct.
Level 15 , Providence, United States
21 June 2020, 16:45
can someone please explain this question to me thank you
Level 15 , Riyadh, Saudi Arabia
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' )
Level 8 , Kosice, Slovakia
7 February 2020, 11:50
When you do this task after all previous in this lesson it is quite easy :)