Assignment No.6

  1. (Adapted from Textbook Chapter 4 Project 1) Write a method called toRoman that accepts an integer between 1 and 3,999 and returns its Roman numeral expression. The letters are:

    I for 1
    V for 5
    X for 10
    L for 50
    C for 100
    D for 500
    M for 1000

    You may read up the rule Roman Numerals in Wikipedia. If the input number is out of range, the method should return the empty String.

  2. (Adapted from Textbook Chapter 4 Exercise 21) Write a method called isPerfectNumber that accepts a positive integer and returns as a boolean whether the number is a perfect number, where a positive number is a perfect number if its divisors excluding itself sum to the number. For example, 28 is such one, because 28 = 1 + 2 + 4 + 7 + 14.

Go back to the assignment list page.