Here is my code:
public static void rightSel(Scanner scanner,char t) { System.out.print(": "); if (scanner.hasNextLine()) { String orInput = scanner.nextLine; if (orInput.equalsIgnoreCase("help") { System.out.println("The following commands are available:"); System.out.println(" 'help' : displays this menu"); System.out.println(" 'stop' : stops the program"); System.out.println(" 'topleft' : makes right triangle alligned left and to the top"); System.out.println(" 'topright' : makes right triangle alligned right and to the top"); System.out.println(" 'botright' : makes right triangle alligned right and to the bottom"); System.out.println(" 'botleft' : makes right triangle alligned left and to the bottom"); System.out.println("To continue, enter one of the above commands."); }
I would like the user to make it clear how they can enter commands, for example: "Top Right", "Top Right", "TOPRIGHT", Top Left, etc. To this end, I try in the last if ( check if cutInput starts with "top" or "up" and checks if cutInput ends with "left" or "right", all being case insensitive. Is this possible?
The ultimate goal is to allow the user in one line of input to select one of the four orientations of the triangle. It was the best way to do this, but I'm still pretty new to programming in general and maybe complicating things too much. If I, and it turns there is an easier way, please let me know.
java string case-insensitive startswith ends-with
Matao Gearsky Nov 07 '14 at 4:51 on 2014-11-07 04:51
source share