java - How to make a string compare non case sensitive? -


i trying write code 1 of programs responds according answers. want make of variables not case sensitive. example if variable x equal "me" want equal "me". possible?

here code far:

import java.util.scanner;  class tutorial {     public static void main (string args[]){         system.out.println("who goes there?");         scanner n = new scanner(system.in);         string name = n.next();         if (name.equals("me") || name.equals("me")){                 system.out.println("well, smartass.");                 system.exit(1);         }else system.out.printf("nice meet you, %s.%n", name);            system.out.print("how doing?");         scanner d1 = new scanner(system.in);         string doing = d1.next();         switch(doing){         case "good": system.out.println("that nice hear.");         case "well": system.out.println("that nice hear.");         case "bad" : system.out.println("that's ruff mate.");         case "awesome" : system.out.println("nice");         case "terrible" : system.out.println("sucks you");          }     } } 

i don't want have make 2 cases each answer 1 uppercase , other lower case.

slightly off topic question. how close resource leaks scanner?

worth mentioning string#tolowercase:

name.tolowercase().equals("me"); 

or use string#equalsignorecase:

name.equalsignorecase("me"); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -