System.out.println( "Great! Now select the type of measurement this is so we can convert!");
System.out.println( "G = Gallons" );
System.out.println( "I = Inches" );
System.out.println( "P = Pound" );
System.out.println( "M = Mile" );
String userType = input.nextLine();
我输入一个数字,然后当我应该输入测量类型时(如上所示),它会自动跳到此后的 if 语句。我尝试过的没有任何效果。有人可以帮忙吗?
最佳答案
你必须
input.nextLine();
在读入数字部分之后,当您从扫描仪读入数字到字符串时
我希望这能在未来发挥作用并为您提供帮助。
关于java - 我正在尝试比较一个字符串,但是当我让用户输入一个字符串时,它不允许他们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22826997/