java - Why does this switch statement not work? -


import java.util.scanner;  public class verticalwire {     public static void main(string[] args)     {           scanner in = new scanner(system.in);         system.out.println("how many wires");         string howmanywires = in.next();          switch(howmanywires) {             case "3":             {                  system.out.println("true");                  break;             }              case "3 5":             {                  system.out.println("false");break;}             }      } } 

i tested if enter "3 5" returns true though think should return false! wrong?

use in.nextline() instead of in.next().

documentation of scanner.next() states that

finds , returns next complete token scanner.

so when enter 3 5 input, read 3 when call next method , if again call next method read 5.


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -