+ 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
6 Answers
+ 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 : )
+ 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?
+ 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
+ 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...
+ 2
yes that's what I'm trying to do