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<>();