Lab 9: Algorithms and Data Structures

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