Question: Exercise 4 . 3 3 Challenge exercise Write a method isPrime ( int n ) that returns true if the parameter n is a prime

Exercise 4.33 Challenge exercise Write a method isPrime (int n) that returns true if the parameter n is a prime number, and false if it is not. To implement the method, you can write a while loop that divides n by all numbers between 2 and (n-1) and tests whether the division yields a whole number. You can write this test by using the modulo operator (**) to check whether the integer division leaves a remainder of 0(see the discussion of the modulo operator in Section 3.8.3).
Exercise 4.34 In the findFirst method, the loop's condition repeatedly asks the files collection how many files it is storing. Does the value returned by size vary from one check to the next? If you think the answer is no, then rewrite the method so that the number of files is determined only once and stored in a local variable prior to execution of the loop. Then use the local
Chapter 4- Grouping Objects
variable in the loop's condition rather than the call to size. Check that this version gives the same results. If you have problems completing this exercise, try using the debugger to see where things are going wrong.
 Exercise 4.33 Challenge exercise Write a method isPrime (int n) that

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!