Sure! Here are the directions I received:
Your task is to write the following program in the GCD.java file. The program first reads in 2 integer numbers a and b. Then the program computes and prints the Greastest Common Divider (GCD) of the numbers a and b.
The GCD of a and b is the largest integer n, such that:
a / n has a remainder 0
AND
b / n has a remainder 0
# More details...
The GCD cannot be computed with some Mathematical formula, but you need to search and find it.
The number of integers is infinite, so you need to limit the range to search.
Use these facts to limit the range:
o The GCD of a and b must be smaller than either one of a or b.
* You program try every number (starting from 1 until the largest one possible) in the possible range and
test if it is a common divider.
A common divider is a number n, such that:
a / n has a remainder 0
AND
b / n has a remainder 0
* Don't forget that you can perform AND, OR and NOT operation of logic values:
o the AND operator is: &&
o the OR operator is: ||
o the NOT operator is: !
* Finding the greatest common divider can be achieved by always keeping the larger common divider if you find a new one.
# Hint
* Try every number starting from 1 upto one of the input numbers (any one of the input numbers will do)
* The program must remember (save it in a variable - memory !) the last number that divides both input numbers
* After you try every number, print out the last number that you have recorded.
[ October 28, 2007: Message edited by: a br ]