我的Java工具类(不断更新)
Scanner(要求用户按要求输入int double 数据) //对输入整数进行优化 public class ScannerUtils { //私有构造方法 private ScannerUtils ( ) { } public static int getInt ( ) { while ( true ) { Scanner sc = new Scanner ( System . in ) ; try { //不搞录入语句了 一般都需要按照题目要求写 return sc . nextInt ( ) ; } catch ( Exception e ) { System . out . println ( "别乱搞" ) ; System . out . println ( "再搞让你蓝屏" ) ; } } } public static double getDouble ( ) { while ( true ) { Scanner sc = new Scanner ( System . in ) ; try { System . out . println ( "输入个数!!!!" ) ; return sc . nextDouble ( ) ; } catch ( Exception e ) { System . out . println ( "别乱搞" ) ; System