allowing multiple user inputs in java -


i making a.i carries on conversation you. when run program, computer says hi, , user can enter multiple greetings (like you, howdy etc.)

my question when computer asks user "how you?" , user answers. programmed switch if "good" computer reply "glad hear it." , doesn't. did wrong?

here code:

    system.out.println("hi");     thread.sleep(3000);      system.out.println("the computer remind reply greeting");      scanner rexy = new scanner(system.in);     string domino = rexy.nextline();       switch (domino){         case "hello":             system.out.println("how you?");             break;          case "hi":             system.out.println("how you?");             break;          case "howdy":             system.out.println("how you?");             break;          case "heyo":             system.out.println("how you?");             break;          case "hello?":             system.out.println("how you?");             break;          case "hey":             system.out.println("how you?");             break;          case "sup":             system.out.println("how you?");             break;          case "good":             system.out.println("glad hear it");             break;          case "great":             system.out.println("glad hear it");             break;          case "awesome":             system.out.println("glad hear it");             break;          case "splendid":             system.out.println("glad hear it");             break;          case "fantastic":             system.out.println("glad hear it");             break;           case "fine":             system.out.println("glad hear it");             break;          case "what's crackalakin?":             system.out.println("how you?");             break;          case "what's turd face?":             system.out.println("that's rude! how you?");             break;      } } 

}

thanks.

you try adding default statement switch, there fallback when answer not recognized; that:

switch (domino) {   //... default:     system.out.println("sorry, don't understand that.");     break; } 

furthermore, can try printing domino string, see being read.

system.out.println(domino); 

also, tip: can join multiple equal case statements in switch so:

switch (domino) {     case "hello":     case "hi":     case "howdy":     case "heyo":     case "hello?":     case "hey":     case "sup":         system.out.println("how you?");         break;     case "good":     case "great":     case "awesome":     case "splendid":     case "fantastic":     case "fine":         system.out.println("glad hear it");         break; } 

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -