gpt4 book ai didi

java - 我正在尝试比较一个字符串,但是当我让用户输入一个字符串时,它不允许他们

转载 作者:行者123 更新时间:2023-11-30 03:57:25 24 4
gpt4 key购买 nike

    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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com