+ 2

Abbreviation arrays

I need to modify this code in order to allow abbreviation to the minimum required unique string. I know it requires nested for loops, but I am having a difficult time. https://code.sololearn.com/c44LYAI1n90A/?ref=app

29th Jan 2018, 12:20 AM
Alejandra Ackers
Alejandra Ackers - avatar
6 Respostas
+ 7
@Gordie, that's true, thanks for coming in, I was uncertain of my suggestion, you know Java better than me : ) @Alejandra, check out @Gordie's answer, I believe it's a great solution : )
30th Jan 2018, 7:58 AM
Ipang
+ 6
I'm not understanding your question clearly, looking at your code I could only guess you want the code to recognize "resu" as "resume", "rest" as "restart"... is that your actual code intention?
30th Jan 2018, 6:48 AM
Ipang
+ 5
@Alejandra, have you tried using substring method? it returns a part of a string, in this case you want only the first four characters of a valid command. You can then compare the input using equalsIgnoreCase against the partial valid command. if(command[i].equalsIgnoreCase(validCommands[0].substring(0, 4))) // code here ... Hth, cmiiw
30th Jan 2018, 7:14 AM
Ipang
+ 3
@lpang I haven't tried that, but it should work! I know there's also a way by using the charAt method and then going thru it in a for loop...
30th Jan 2018, 7:18 AM
Alejandra Ackers
Alejandra Ackers - avatar
+ 2
yes that's what I'm trying to do
30th Jan 2018, 6:49 AM
Alejandra Ackers
Alejandra Ackers - avatar