Home Java Java-tips Examples-introductory Dialog Programming: Prime Numbers - Dialog

Ask Questions?

View Latest Questions


 
 

Programming: Prime Numbers - Dialog
Posted on: July 26, 2006 at 12:00 AM
Write a program that reads an integer from the user, and displays a message about whether or not it's a prime number.

Java Notes

Programming: Prime Numbers - Dialog

Name ________________________________________

Description

Write a program that reads an integer from the user, and displays a message about whether or not it's a prime number.

Prime numbers are integers which can not be divided evenly by any other integers except 1 and themselves. For example, some of the first prime numbers are 2, 3, 5, 7, 11, 13, 17, ...

Prime numbers have many interesting (at least to mathematicians) properties. More recently they figure prominently in computer encryption schemes, which make use of the fact that it can take a lot of computing power to tell if a number is prime or not.

Hint. The easiest way to decide if n is prime or not is to try dividing it by all integers from 2 to n-1. If any of them can divide it evenly, it's not prime. This isn't efficient, and can't be used for really large numbers (ie, those used in encryption), but it's simple.

Related Tags for Programming: Prime Numbers - Dialog:
cmathcomideencryptionrestpropertiesdivioschememakeintegersednumbersvinumberintthisidsimplelargecomputerifforieexampletoencryptexampowerciastintegerseitffinotcanputusepeimmanfromfirstcecryptinnorealasmnttrstiminoscaminosinterestinghintcomputingesememscomputeallmeprotiexawhichwerxamptryssoatanykisirhaimellivncrmplproperdivideeaexceptandaractrtropesimutissrithavstargeatihatfactmanypleplpropprmimsendonomonl