6. Write a method that meets the requirements of the following comment header bl
ID: 3718559 • Letter: 6
Question
6. Write a method that meets the requirements of the following comment header block.
//
// isMultiple
//
// The purpose of this method is to find whether or not the first
// integer provided is a multiple of the second integer. In other
// words, when the first integer is divided by the second, is the
// remainder zero?
//
// Input Argument: a the first integer
// b the second integer
// Return Value: multiple a boolean value representing whether or not
// the first integer is a multiple of the second
// 7. Write a method that meets the requirements of the following comment header block. This method should use the method created in the previous problem.
//
// findLastMultiple
//
// The purpose of this method is to find the last appearance of a
// multiple value within an array. When found, the method returns the
// index number of the value in the array. If a multiple is not found, the
// method returns -1.
//
// Input Arguments: values the array of values
// n check for multiples of this number
// Return Value: index the index of the final multiple in the array,
// or -1 if no multiple is found
Explanation / Answer
public class Utility { //6. Write a method that meets the requirements of the following comment header block. // // isMultiple // // The purpose of this method is to find whether or not the first // integer provided is a multiple of the second integer. In other // words, when the first integer is divided by the second, is the // remainder zero? // // Input Argument: a the first integer // b the second integer // Return Value: multiple a boolean value representing whether or not // the first integer is a multiple of the second public static boolean isMultiple(int a, int b) { return a % b == 0; } // 7. Write a method that meets the requirements of the following comment header block. This method should use the method created in the previous problem. // // findLastMultiple // // The purpose of this method is to find the last appearance of a // multiple value within an array. When found, the method returns the // index number of the value in the array. If a multiple is not found, the // method returns -1. // // Input Arguments: values the array of values // n check for multiples of this number // Return Value: index the index of the final multiple in the array, // or -1 if no multiple is found public static int findLastMultiple(int[] arr, int n) { int index = -1; for(int i = 0; iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.