| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Java Exercises - Repetition

Page history last edited by Steve Sweeney 14 years, 2 months ago
  1. 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:

    1. Keep asking the user for integers until they terminate the program (e.g., by entering a negative number or zero).
    2. An alternate program would let the user specify a range of numbers, and all prime numbers in the range would be displayed.

       

  2. 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.

     

  3. 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

     

  4.  

Comments (0)

You don't have permission to comment on this page.