Ecco il mio codice:Come si ignora il caso quando si utilizza startsWith e endsWith in Java?
public static void rightSel(Scanner scanner,char t)
{
/*if (!stopping)*/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.");
}//help menu
else if (orInput.equalsIgnoreCase("stop")
{
System.out.println("Stopping the program...");
stopping = true;
}//stop command
else
{
String rawInput = orInput;
String cutInput = rawInput.trim();
if (
mi piacerebbe permettere all'utente certo margine di manovra per come possono immettere i comandi, le cose come: In alto a destra, in alto a destra, topright, in alto a sinistra, ecc A tal fine, sto provando a, a quell'ultimo if (
, controllare se cutInput
inizia con "top" o "up" E verificare se cutInput
termina con "left" o "right", il tutto senza maiuscole/minuscole. È possibile?
L'obiettivo finale di questo è consentire all'utente, in una riga di input, di scegliere uno dei quattro orientamenti di un triangolo. Questo era il modo migliore in cui potessi pensare di farlo, ma sono ancora abbastanza nuovo alla programmazione in generale e potrebbe complicare le cose. Se lo sono, e si trasforma in un modo più semplice, faccelo sapere.
Utilizzare 'command.toLowerCase(). StartsWith (" up ")' e 'command.toLowerCase(). EndsWith (" right ")'. – Tom