Write a program named Remainder.java then implement the following method: public static int divisibleBy(int[] arr, int M, int K) this method determines the number of elements in the int array (arr) that are divisible by M but not K. Then write code inside main method to test your method: your main method accepts three numbers from the command argument list, N, M, K, use the first number to create int array with size of N, assign random number between 0 and Integer.MAX_VALUE [0,Integer.MAX_VALUE) , then call your method to determine and then print how many numbers are divisible by M but not K
Thanks for the question, here is the complete code in Java.
import java.util.Random;
public class Remainder {
public static int
divisibleBy(int[] arr, int M,
int K) {
int
count = 0;
for
(int i = 0; i < arr.length;
i++) {
/// condition to check if its divisible by M but not K
if (arr[i] % M == 0 && arr[i] % K != 0)
{
count += 1;
}
}
return
count;
}
public static void
main(String[] args) {
int N =
100;
int M =
5;
int K =
7;
int[]
arr = new int[N];
Random random =
new Random();
for
(int i = 0; i < N; i++) {
// generating a random number between 0 and MAX INT and storing
it in array
arr[i] =
random.nextInt(Integer.MAX_VALUE);
}
int
counts = divisibleBy(arr, M, N);
System.out.println("Count:
"+counts);
}
}
================================================================================
Write a program named Remainder.java then implement the following method: public static int divisibleBy(int[] arr, int...
Write a program named Review.java and implement the following two methods: public static int NumberOfElementsLessThanAverage(int[] arr) that returns the number of elements that are less than the average of all elements of the array. public static int[] countChars(File file), this method reads data from a file and counts the frequency of each alphabetic letters, and returns those numbers as an int array. the data file name is "data.txt"
Our 1st new array operation/method is remove. Implement as follows: public static boolean remove( int[] arr, int count, int key ) { 1: find the index of the first occurance of key. By first occurance we mean lowest index that contains this value. hint: copy the indexOf() method from Lab#3 into the bottom of this project file and call it from inside this remove method. The you will have the index of the value to remove from the array 2:...
Write a public static method named getMaxOf2Ints that takes in 2 int arguments and returns the Maximum of the 2 values Write a public static method named getMinOf2Ints that takes in 2 int arguments and returns the Minimum of the 2 values Write apublic static method named getMaxOf3Ints that takes in 3 int arguments and returns the Maximum of the 3 values Write a public static method named getMedianOf3Ints that takes in 3 int arguments and returns the Median Value...
must provide the following public interface: public static void insertSort(int [] arr); public static void selectSort(int [] arr); public static void quickSort(int [] arr); public static void mergeSort(int [] arr); The quick sort and merge sort must be implemented by using recursive thinking. So the students may provide the following private static methods: //merge method //merge two sorted portions of given array arr, namely, from start to middle //and from middle + 1 to end into one sorted portion, namely,...
You will implement the following method public static int[] linearSearchExtended(int[][] numbers, int key) { // Implement this method return new int[] {}; } There is a utility method provided for you with the following signature. You may use this method to convert a list of integers into an array. public static int[] convertIntegers(List<Integer> integers) Provided code import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Scanner; public class MatrixSearch { // This method converts a list of integers to an array...
Write a static, void method named replaceAll that accepts an array of int's named numbers as well as an int named num. The method must replace all occurrences of num . that are found in even-numbered index portions with the value of 3. That is, if the value num is stored in numbers [4] then it must be replaced with the value of 3 since 4 is an even number. But if num is found in numbers[5], it must not...
1) Write a public static method named printArray, that takes two arguments. The first argument is an Array of int and the second argument is a String. The method should print out a list of the values in the array, each separated by the value of the second argument. For example, given the following Array declaration and instantiation: int[] myArray = {1, 22, 333, 400, 5005, 9}; printArray(myArray, ", ") will print out 1, 22, 333, 400, 5005, 9 printArray(myArray,...
this program is in C.
Write a program that computes the number of elements in an array divisible by a user specified number. Declare an integer array of size 7 and read the array elements from the user. Then, read a number k from the user and compute the number of elements in the array divisible by k. Consider the following example. 3 elements in this array are divisible by 2 ({2,2,4}). Sample execution of the program for this array...
Design and implement a Java program (name it ArrayMethods), that defines 4 methods as follows: int arrayMax (int [ ] arr) determines and returns the maximum value within an array int arrayMin (int [ ] arr) determines and returns the minimum value within an array void arraySquared (int [] arr) changes every value within the array to value2 void arrayReverse (int [ ] arr) reverses the array (for example: 7 8 12 becomes 2 18 7) Test your methods by...
the code needs to be modifed. require a output for the
code
Java Program to Implement Insertion Sort import java.util.Scanner; /Class InsertionSort * public class Insertion Sort { /Insertion Sort function */ public static void sort( int arr) int N- arr.length; int i, j, temp; for (i-1; i< N; i++) j-i temp arrli; while (j> 0 && temp < arrli-1) arrli]-arrli-1]; j-j-1; } arrlj] temp; /Main method * public static void main(String [] args) { Scanner scan new Scanner( System.in...