0

Learning to use isPrime() method to check for prime number

Write a method called isPrime that takes in one integer parameter X and determines whether or not X is prime. The method should return boolean value: return true if X is a prime number. To test this method, I want to write a main() routine that asks the user to input a positive integer N. Using the isPrime() method, find and print all the prime numbers less than or equal to N, where the output has 9 numbers per line

1st Mar 2019, 5:01 AM
Gary Hu
Gary Hu - avatar
1 Resposta
+ 3
First things first, how do you determine a prime number? A prime number has 2 factors: the numbers 1 and itself. This should be the first thing that you should tackle. Finding out all the numbers up to N means you just need to run a loop and check each number with the isPrime() method.
1st Mar 2019, 5:11 AM
Lambda_Driver
Lambda_Driver - avatar