0

How to print Strings from the longest to the shortest from table using lenght()? Java

I have table like this: public class excersise { public static void main(String[] args) { String[] table = new String[3]; table[0] = " i eat "; table[1] = "i eat apple"; table[2] = "i eat egg"; And my taks is to print Strings from the longest to the shortest one with using lenght() and i need to have white spaces in some, like this: " i eat " So the output should be: i eat apple i eat egg i eat

22nd May 2021, 3:44 PM
Martyna Tomaszewska
Martyna Tomaszewska - avatar
1 Réponse
0
Use sorting techniques (algorithms). Here simple bubble sort works.. Swap values at i'th index value with I+1 indexed value if table[I].length()<table[I+1].length() is true.. repeat it until no more swaps.. (bubble sort).. See these ones: https://www.sololearn.com/learn/774/?ref=app
22nd May 2021, 7:05 PM
Jayakrishna 🇮🇳