原因分析:https://blog.csdn.net/w252064/article/details/78471267
改进方法:(输入的字符串想要待空格时)(输入的字符串不需要空格时,可用直接用sc.next)
1.在nextInt后,nextLine前 提前加入sc.nextLine();
2.如上方链接文章的方法中:进行string和int的转换
3.使用BufferedReader类
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
String text = buffer.readLine();
在方法中需要抛出io异常java.io.IOException