7.18 zyLab: Count Multiples Complete the following method to return the number o
ID: 3909567 • Letter: 7
Question
7.18 zyLab: Count Multiples Complete the following method to return the number of multiples of digit between low and high (inclusive). For example, there are 5 multiples of 2 between 1 and 10, Use the % operator to determine if a number is an even multiple of digit. Use a for loop to test each number between low and high LAB 718.1: zyLab: Count Multiples 0/2 ACTIVITY Main.java Load default template... 1 public class Main 3 public int countMultiples(int low, int high, int digit)I 4 Type your code here. 9 public static void main(String args) 10 Main test- new MainO test.countMultiples(5, 100, 7; 12 13 14Explanation / Answer
Main.java
public class Main {
public int countMultiplies(int low, int high, int digit) {
int count = 0;
for(int i=low;i<=high;i++) {
if(i % digit == 0) {
count++;
}
}
return count;
}
public static void main(String[] args) {
Main test = new Main();
int count = test.countMultiplies(5, 100, 7);
System.out.println(count);
}
}
Output:
14
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.