你可以考虑用 sc.hasNextLine() 来判断到底有没有下一行。 看代码:
while(sc.hasNextLine()){ str=sc.nextLine(); //... }
你都没有输入啊y或n