题目:输入一组数N和数字b ,求出该组数字中能被b 整除的个数。
示例:
输入
1 2 3 4 5 6
2
输出
3
public class ExactDivision {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Please input a array nums:");
String str = scan.nextLine(); //nextLine会获取到带有空格的字符串,并把回车符吃掉,而next会自动把字符串中的空格过滤掉
System.out.println("Please input a division again:");
int div = scan.nextInt();
String[] strs = str.split(" ");
int result = 0;
for (int i = 0; i < strs.length; i++) {
if(Integer.valueOf(strs[i]) % div == 0){
result++;
}
}
System.out.println("这组数中能被2整除的个数:"+ result);
scan.close();
}
}