Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions