请解释这里发生的事情,因为我不明白什么会增加......
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] a = new int[100];
for(int a_i=0; a_i < n; a_i++){
a[in.nextInt()]++; //here
}
答案 0 :(得分:1)
您将扫描仪绑定到系统输入(键盘)。
Scanner in = new Scanner(System.in);
从键盘请求整数n
:
int n = in.nextInt();
声明一个包含100个int元素的数组(从0到99)
int[] a = new int[100];
和
// Running a loop from 0 to the entered n value.
for(int a_i=0; a_i < n; a_i++){
// requesting an int number from keyboard in in.nextInt()
// and incrementing array element with the index obtained in in.nextInt()
a[in.nextInt()]++;
}
a[in.nextInt()]++;
可以转换为代码:
int idx = in.nextInt();
a[idx]++;