With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

No credit card required

Chapter 15. Prime Numbers

Prime numbers have fascinated professional and amateur mathematicians alike since ancient times. It's a simple concept—a prime number is any integer greater than 1 that is divisible only by 1 and itself. An integer greater than 1 that is not prime is composite. In this chapter, we'll use Java to explore two topics related to prime numbers.

The first topic is primality testing. Given a positive integer, how can we tell whether it is prime or composite? Of course, we can systematically try dividing the number by a succession of “trial divisors”—if we find a divisor other than 1 and the number itself that divides evenly into the number (the division leaves no remainder), then the number is composite. If we fail to find such ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

No credit card required