|
Java Exercises - Repetition
Page history
last edited
by Steve Sweeney 14 years, 2 months ago
- A prime number is a positive integer that has exactly two distinct divisors - one and the number itself. For example, 17 is a prime number because it is divisible only by 1 and 17. Write a program that reads an integer and then prints a message stating whether or not it is a prime number.
Improvements:
- Keep asking the user for integers until they terminate the program (e.g., by entering a negative number or zero).
- An alternate program would let the user specify a range of numbers, and all prime numbers in the range would be displayed.
- The number 153 has the property that it is equal to the sum of the cubes of its digits: 1^3 + 5^3 + 3^3 = 153. Write a program that will find al the three-digit natural numbers (positive integers) that have this property.
- Write a program that reads a positive integer, n, and then prints its digits in a column. For example, if n=3467, then the program should print
3
4
6
7
-
Java Exercises - Repetition
|
Tip: To turn text into a link, highlight the text, then click on a page or file from the list above.
|
|
|
Comments (0)
You don't have permission to comment on this page.