Scanner的操作
next():读取以空格为结束符
nextDouble(),nextFloat(),nextInt()
nextLine():读取以换行为结束符,读取的是字符串
hasNext():判断是否有输入
hasNextLine():判断是否有下一行
知道固定长度
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int[] a = new int[N];
for(int i = 0;i < N;i++){
a[i] = sc.nextInt();
}
不知道固定长度
Scanner sc = new Scanner(System.in);
String[] nums = null;
nums = sc.nextLine().split(" ");
int[] num = new int[nums.length];
for(int i = 0;i < num.length;i++){
num[i] = Integer.valueOf(nums[i]);
}