Question: Write ( define ) a public static method named countDivisible 3 or 5 , that takes two int arguments and returns an int value. You
Write define a public static method named countDivisibleor that takes two int arguments and returns an int value. You can safely assume that the second argument value will be greater than the first argument value. When this method is called, it should count all of the values between the first argument value and the last argument value inclusive that are evenly divisible by either or Your method should return this count.
Examples:
countDivisibleor will return because there are numbers between and that are evenly divisible by either or These numbers are countDivisibleor will return because there are numbers between and that are evenly divisible by either or These numbers are countDivisibleor will return because there are no numbers between and that are evenly divisible by either or
You may wish to write some additional code to test your method
Helpful Hints:
Use a counter controlled while loop to iterate from the first argument value to the second argument value. As you iterate, use an if statement to test whether or not each value is either evenly divisible by or Keep track of the count of how many numbers between the first argument value to the second argument value are evenly divisible by either or Return that count when the loop is finished.
a Java for loop would also be a reasonable choice here.
Remember that you can use the modulus operator to compute the reminder of an integer division operation.
For example: : is because goes into evenly with no remainder. On the other hand, is because goes into two times with left over.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
