Lab 9: Algorithms and Data
Structures
- Review Lecture 10.
- Create an empty directory named
javalab9/
in
your directory.
- Recursion: Create a
text-based Java application named GCD.java.
- A gcd() method
should recursively compute the greatest common divisor of the two
integers.
- Use the code given in Lecture 10.
- Add a println statement at the beginning of the method to
print the arguments a and b.
- The main() method
should
- take two integers from the command line.
- call gcd() with
the two command-line arguments and print the result.
- Sorting and Searching:
Create a text-based Java application named Sort.java.
- Check the Arrays documentation in java.util in the jdk 1.3
docs API.
- Create an array of unsorted integers, e.g. int[] a = { 32, 10, 63, 23, 91, 10,
28, 14 };
- Print every element in the array, e.g. using a for loop.
- Sort the array using Arrays.sort(a);
- Search for a number that is in the array using int result = Arrays.binarySearch(a,
number);
- Print the result, which is the position of the number in the
array.
- Search for a different number that is not in the array.
- Print the result, which is the insertion point where the
number would be added.
- Compress the folder using the Ark archiving program to
produce
javalab9.zip
.
- Send the
javalab9.zip
file to gvogl@umu.ac.ug as an attachment in a
message with subject java lab 9.