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.
For each test case, output a single line containing the answer.
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]);}
}
}
Comments
Leave a comment