Answered step by step
Verified Expert Solution
Question
1 Approved Answer
3. (25 pts) For each of the following two problems, you are given the method: public static boolean isPrime (int i) which returns true
3. (25 pts) For each of the following two problems, you are given the method: public static boolean isPrime (int i) which returns true if and only if i is prime. (a) Write a static method that takes an array and returns true if and only if all elements of the array are prime. public static boolean allPrime (int () a) { } (b) Write a static method that removes all non-prime numbers from an array, putting all the prime numbers on the left and filling in with zeros on the right. The prime numbers keep their original order. The method must modify the given array and return void. For example, given array [4, 7, -2, 17, 51, 23], after executing this method the array contains [7, 17, 23, 0, 0, 0]. Hint: An easy and succinct way to do this is to add the primes to an ArrayList as you discover them while simultaneously zeroing out the input array, then copying the ArrayList back. public static void move PrimesLeft (int [] a) { }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started