从键盘接收数据,每次只能一次,怎么样让多次接收数据
各位大神,请多多指教
各位大神,请多多指教
2019-07-04
public static void sustainedInput() { System.out.println("请输入连续录入的次数:"); Scanner sc = new Scanner(System.in); int[] arr = new int[sc.nextInt()]; // 根据输入的次数来定义对应数组的长度 System.out.println("请在输入正确的数值之后按下ENTER键,并且继续输入:"); //使用循环持续输入,并且对数组进行赋值 for (int i = 0; i <= arr.length - 1; i++) { int num = sc.nextInt(); arr[i] = num; } //查看输入的是否正确 System.out.println("你输入的数值是:"); for (int i = 0; i < arr.length; i++) { System.out.println(arr[i]); } }
举报