Write a method that takes a single int argument (which will
be a positive integer) and returns true if the number is prime and false
if it is not. A number is prime if it is greater than 1 and not divisible
by any number other than 1 and itself. Note that 1 is not prime.
Thus you can test whether a number greater than 1 is prime by checking
whether it is divisible by any smaller number greater than one. (As a
useful optimization, note that you only need to test numbers up to and
including the square root of the number you are checking. Remember you can
get the square root of a number with the Math.sqrt method.)
Write a method that takes a single int argument and returns
the number of primes less than that number.
Twin primes are pairs of primes that have only one number between them.
For instance 3 and 5 are twins. Write a method that takes a
single int argument and returns the number of twin prime
pairs with the first twin less than that number.
Super primes are prime numbers whose position in the list of all primes is also a prime number. For instance 3 is a super prime because it is the second prime number, i.e. it’s at position 2, and 2 is a prime number. Likewise, 5 is because it’s the third prime number. But 7 is not because it’s the fourth prime and 4 is not prime. (Note that the “positions” in the list of primes are normal human numbers that start at 1, not programmer numbers that start at 0, so 2 is at position 1, 3 is at position 2, and so on.
Write a method that takes a single int argument and returns
a boolean indicating whether the number is a super prime.
Some methods using loops.