Final answer:
To solve the student's question, implement the countMultiples method using a for loop to count the multiples of x between low and high, and then call this method from the main function after getting user input.
Step-by-step explanation:
To complete the program, you must fill in the countMultiples method within the Count class. This method will calculate the number of multiples of x between two integers, low and high. The method will use a for loop to iterate through the numbers, checking each one to see if it's a multiple of x using the modulo operator (%).
Here's how you can define the countMultiples method:
public int countMultiples(int low, int high, int x) {
int count = 0;
for (int i = low; i <= high; i++) {
if (i % x == 0) {
count++;
}
}
return count;
}
In the main method, you'll need to read three integers from the user input and invoke the countMultiples method, finally printing out the result:
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int low = scnr.nextInt();
int high = scnr.nextInt();
int x = scnr.nextInt();
Count myCount = new Count();
int result = myCount.countMultiples(low, high, x);
System.out.println(result);
}