For each of the problems we will show just the method that solves the problem. At the end we give a program that tests all the individual methods.
| |||
Problem 01 | |||
|
Write a method which prints the numbers from 1 to 50.
| |||
Problem 02 | |||
Write a method which takes an int as a parameter and
prints the numbers from 1 to that value. Note this method does not
get input from the user, it gets its value from the method which calls
it.
| |||
Problem 03 | |||
Write a method which takes an int as a parameter and
returns the sum of the numbers from 1 to that value. Note that this
method does not get input from the user. It also does not
display anything for the user. It simply returns its result to the
method which called it.
| |||
Problem 04 | |||
Write a method which takes two int values as parameters
and returns the larger of the two.
| |||
Problem 05 | |||
Write a method which takes two int values as parameters
and uses
Euclid's method
to compute and return their greatest common divisor.
| |||
Unified Solution: | |||
| |||
Last modified August 28 for Fall 99 cs5 by fleck@cs.hmc.edu
This page copyright ©1998 by Joshua S. Hodas. It was built with Frontier on a Macintosh . Last rebuilt on Thu, Nov 5, 1998 at 8:15:54 PM. | |
http://www.cs.hmc.edu/~hodas/courses/cs5/week_07/labsolutions.html | |