about | help | code help+videos | done | prefs |
Given an int input, determine if it is a prime number and return true if it is prime, false if not. Remember that a prime number is one that can be only divided by 1 and itself. One way of realizing this is that for some input num, num % 1 == 0 and num % num == 0 but num % (something between 1 and num) != 0. That is to say, when dividing by any number other than 1 and num, the remainder will be positive. Precondition: num > 1. HINT: num/2 is definitely the upper boundary on the numbers you have to check, since a number will never be divisible by something 2/3 its size. HINT: Assume that the number is prime (that you will return true). If you find a counter-example (a reason to not return true), change the value of your output variable. This is a common pattern where you assume a certain output, then change your mind if you have a reason to do so while processing a method.apcsaLoopsIsPrime(2) → true apcsaLoopsIsPrime(9) → false apcsaLoopsIsPrime(11) → true ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 150
Copyright Nick Parlante 2017 - privacy