Question: Exercise 4 . 3 3 Challenge exercise Write a method isPrime ( int n ) that returns true if the parameter n is a prime
Exercise Challenge exercise Write a method isPrime int that returns true if the parameter is a prime number, and false if it is not. To implement the method, you can write a while loop that divides by all numbers between and 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 see the discussion of the modulo operator in Section
Exercise 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 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.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
