Answer to Question #249658 in Java | JSP | JSF for Tarurendra Kushwah

Question #249658

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.

Input

  • The first line of the input contains an integer T denoting the number of test cases. The description of each test case follows.
  • The first line of each test case contains three space separated integers: NX and Y.
  • The second line contains N space-separated integers A1A2, ..., AN denoting the array A.

Output

For each test case, output a single line containing the answer.

Constraints

  • 1 ≤ T ≤ 10
  • 1 ≤ N ≤ 105
  • 1 ≤ A1, A2, ... ,AN ≤ 109
  • 1 ≤ X, Y ≤ 109







1
Expert's answer
2021-10-11T07:00:20-0400
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) {
	    Scanner input=new Scanner(System.in);
	    System.out.println("Enter the three intergers X Y and N respectively: ");
	    int X=input.nextInt();
	    int Y=input.nextInt();
	    int N=input.nextInt();
		int [] A = new int [5];
		System.out.print("Enter the elements of the array: ");
	    A[0] =input.nextInt();
	    A[1]=input.nextInt();
	    A[2]=input.nextInt();
	    A[3]=input.nextInt();
	    A[4]=input.nextInt();
        System.out.println("The numbers of the array divisible by Y and less than or equal to X are: ");
		if(A[0]%Y==0 && A[0]<=X){
		    System.out.println(A[0]);}
		 if(A[1]%Y==0 && A[1]<=X){
		    System.out.println(A[1]);}
		 if(A[2]%Y==0 && A[2]<=X){
		    System.out.println(A[2]);}
		 if(A[3]%Y==0 && A[3]<=X){
		    System.out.println(A[3]);}
		 if(A[4]%Y==0 && A[4]<=X){
		    System.out.println(A[4]);}
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS