Respuesta :
Following are the Java Program to the given question:
import java.util.Scanner; //import package for user-input
public class Count //defining a class Count
{
public static int countMultiples(int low,int high,int x)//defining a method countMultiples that takes three integer parameters
{
int c=0,i; //defining integer variables that hold value
for(i=low;i<=high;i++)//defining loop that iterates value between low and high
{
if(i%x==0)//defining if block that uses % operator to check value
{
c+=1; //incrementing c value
}
}
return c; //return c value
}
public static void main(String[] args)//main method
{
int l,h,x;//defining integer variable
Scanner scnr=new Scanner(System.in); //creating scanner class object
l=scnr.nextInt(); //input value
h=scnr.nextInt();//input value
x=scnr.nextInt();//input value
System.out.println(countMultiples(l,h,x)); //calling method and print its value
}
}
Output:
Please find the attached file.
Program Explanation:
- Import package.
- Defining a class "Count", and inside the class two method "countMultiples and main method" is declared.
- In the "countMultiples" method three integer parameter that are "low, high, and x".
- Inside this method a for loop is declared that uses the parameter value and use conditional statement with the % operator and check and return its values.
- Inside the main method three integer variable is declared that uses the scanner class to input the value and pass to the method and print its calculated value.
Learn more:
brainly.com/question/16106262