and It would be awesome if someone can help me.
I'm trying to use the Split command of Java, to split a String using the space BUT the problem is, that maybe the string won't have a space, that means it will be just a simple order (instead of "enter 2" it will be "exit")
Scanner SC = new Scanner(System.in);
String comando = SC.nextLine();
String[] comando2 = comando.split("\\s+");
String first = comando2[0];
String second = comando2[1];
When i try this, it works if I write "enter 3" because "first = enter" and "second = 3", but if I write "exit" it throws an error, because second doesn't have a value. I would like to split the String, so when i try to this the following:
if ( comando.equalsIgnoreCase("exit"))
// something here
else if ( first.equalsIgnoreCase("enter"))
// and use String "second"
Can someone help? Thank you!
//instead of/).ifclauses), which does some implicit checking.