0
当我运行上面的代码时,它跳过第一个输入字符串并且不接收输入字符串,它打印hs.size()并跳转到n = 2但是从n = 2开始,代码运行得非常好。它将输入字符串并添加到哈希集中。为什么在上面的代码中跳过n = 1的输入字符串
为什么它跳过n = 1的输入字符串? 请帮忙。
public class ch
{
public static void main(String[] args)
{
HashSet hs=new HashSet();
String s;
Scanner console=new Scanner(System.in);
int n=console.nextInt();
for(int i=0;i<n;i++)
{
s=console.nextLine();
hs.add(s);
System.out.println(hs.size());
}
}
}
提示:保存一些混淆,并尝试几乎总是使用'nextLine'并执行' parseInt'之后 –