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;}
}
}
}
我测试过,如果输入“3 5”,它会返回true,即使我认为它应该返回false! 有什么不对?为什么这个switch语句不起作用?
你觉得呢'in.next() '是吗?你为什么这么认为? –
'in.next()'只读取第一个数字。使用'nextLine()' – TheLostMind
阅读['Scanner#next'](https://docs.oracle.com/javase/8/docs/api/java/util/Scanner.html#next--)实际上,然后使用'扫描仪#nextLine'而不是 – MadProgrammer