Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 方法在不接受用户输入的情况下运行_Java_Methods_Input - Fatal编程技术网

Java 方法在不接受用户输入的情况下运行

Java 方法在不接受用户输入的情况下运行,java,methods,input,Java,Methods,Input,嘿,伙计们,我正在写这个程序,我对这个方法有一个问题 public int titlesearch() { System.out.println("What is the title of the game you want to search for?"); String searchkey; searchkey =input.nextLine(); String titlekey=searchkey.toLowerCase(); for (int i=

嘿,伙计们,我正在写这个程序,我对这个方法有一个问题

public int titlesearch()
{
    System.out.println("What is the title of the game you want to search for?");
    String searchkey;
    searchkey =input.nextLine();
    String titlekey=searchkey.toLowerCase();
    for (int i=0;i<gamelist.size();i++)
    {
        String gametitle=gamelist.get(i).getTitle();
        if (gametitle.equals(titlekey) && gamelist.get(i).getSelling()== true)
            {
                System.out.println("Game is found!");
                return i;
            }
    }
    return -1;
}
public int titlesearch()
{
System.out.println(“您要搜索的游戏名称是什么?”);
字符串搜索键;
searchkey=input.nextLine();
String titlekey=searchkey.toLowerCase();

对于(int i=0;i您这样做应该没问题,我看不出有什么理由跳过您的输入行。我在Windows和Linux上以及在命令行和eclipse中尝试并执行了它,每次都很好

我能想象的唯一原因是,你的输入缓冲区中已经有东西了,但我不知道为什么。你如何启动你的程序,在哪个环境下

附言:一个小提示,不要用小写字母来命名你的类,所以它应该是
Gameprofile
或者更好的
Gameprofile
,而不是
Gameprofile

 Scanner input=new Scanner(System.in);
 List<gameprofile> gamelist= new Arraylist<>();