Given an array A of N integers and two integers X and Y, find the number of integers in the array that are both less than or equal to X and divisible by Y.
import java.util.Scanner;
public class App {
public static void main(String[] args) {
Scanner keyBoard = new Scanner(System.in);
int t = keyBoard.nextInt();
while (t > 0) {
int n = keyBoard.nextInt();
int x = keyBoard.nextInt();
int y = keyBoard.nextInt();
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = keyBoard.nextInt();
}
int count = 0;
for (int i = 0; i < n; i++) {
if (a[i] <= x && a[i] % y == 0) {
count++;
}
}
System.out.println(count);
t--;
}
keyBoard.close();
}
}
Comments
Thank you it's worked.
Leave a comment