Language Fundamentals

Exercises


  1. Copy the the class Cell.java into a file Cell.java. Compile and run the Program.
  2. Try out the documentation tool:
  3. Inspect the Java class documentation provided by the JDK. You will find it via the OOAD home page (http://www.sts.tu-harburg.de/teaching/ws-98.99/OOA+D/entry.html) or directly at (http://pc01.sts.tu-harburg.de/javadoc/api/packages.html). Search the classes Integer and Boolean which are direct object counterparts to the primitive types int and boolean. Write a test program that converts an int value to an Integer object (and vice versa) and an bool value to a Boolean object.
  4. Write a program that defines variables for each primitve type (int, float, boolean, char), carries out one of the described operations (see handout), and prints the results.
  5. Write a program that prints values from one to 100. Avoid printing the values divisible by 13 and let the program print the string "Bad Luck" instead.
  6. Create a program to print the alphabet in lower case, explicitly marking the letters which are contained in the words "java" or "programming". Note that the letter 'a' is in both words. Nest a switch statement into a for loop for this purpose.
  7. Write a program that computes the prime numbers less than 1000.
  8. **Try to improve your programm by employing the Sieve of Eratosthenes:
    The basic idea of the Sieve is to provide one boolean (or bit) for each number from 1 to n (array of n booleans)  when you want to compute all the prime numbers less than n. Initially all these values are set to true. Whenever a prime number is discovered the array entry related with this number and those related with its multiplicities are set to false. Proceeding like this the next entry in the array equal to true is the next prime number. Define a class Sieve to implement the sieve.

Software Systems Institute

Home of the Java Course Ulrike Steffens, may 1998