← Back to Methods
Question 286
Check if a Number Is Prime
Check if a Number Is Prime
Create a class named PrimeChecker with a public static method IsPrime that takes one integer n and returns a bool telling whether n is a prime number. A prime is a whole number greater than 1 that has no divisors other than 1 and itself. Numbers less than 2 are not prime. Combine a loop with a divisibility check: if any value between 2 and n divides n evenly, it is not prime. For example, IsPrime(7) returns true and IsPrime(10) returns false.
Expected Output:
True= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Methods
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cw, cr, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.