java中switch语句实际的执行顺序:
https://blog.csdn.net/geek_zhang/article/details/74941026
解决办法:在每一个case语句后添加break或者continue语句
java中scanner输入为什么会被跳过:
https://blog.csdn.net/sun8112133/article/details/84350216
原因:输入int型数据,敲击回车之后,程序并不会接收之后的newline ' ' , ' '会被之后的String接手,从而跳过
解决办法:在后面加一个接受字符的语句来接收 ' '
Scanner key = new Scanner(system.in);
key.nextLine();
Java中scanner close方法慎用的问题:
https://blog.csdn.net/namewdy/article/details/105730573
解决办法:
- 全局使用一个scanner对象,并且只在整个程序运行结束的时候只关闭一次scanner。(推荐)在程序一开始时创建,在程序结尾的时候关闭
- 使用完不关闭,需要使用的地方再次创建。
方法:方法就是一段代码片段,是一段可以重复调用,具有特定功能的代码片段