【发布时间】:2016-01-13 09:59:23
【问题描述】:
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! 怎么了?
【问题讨论】:
-
你认为
in.next()是做什么的?你为什么这么认为? -
in.next()只读取第一个数字。使用nextLine() -
阅读
Scanner#next的实际作用,然后改用Scanner#nextLine
标签: java string switch-statement hashcode