id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

orion.a.smith@gmail.com apcsa-loops > apcsaLoopsIsPrime
prev  |  next  |  chance

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.

apcsaLoopsIsPrime(2) → true
apcsaLoopsIsPrime(9) → false
apcsaLoopsIsPrime(11) → true

...Save, Compile, Run (ctrl-enter)

public boolean apcsaLoopsIsPrime(int num) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 150

Copyright Nick Parlante 2017 - privacy