A Prime number is defined as a number that may only be divided by 1 and itself.
ID: 3700464 • Letter: A
Question
A Prime number is defined as a number that may only be divided by 1 and itself. The simplest method of checking of the primality of a number is to perform trial division. This involves dividing the alleged prime number (n) by each integer starting from 2 up until its square root. If it is evenly divisible (remainder of 0) by any of the test integers then it is not a prime number. You will write a public static method named isPrime that tests the primality of some int parameter (int n) and returns a boolean result. Use a for-loop to accomplish this. For full credit, you must include the correct method header (as described) and the correct algorithm. Partial credit is possible. You do not need to write a driver class or method, only the method isPrime Hint: use Math.sqrt(int x) to get the square root of an integer.