Spring Semester 2002


Practical Exam: The Actual Problems.
Here are the actual programs that have been distributed for the midterm:

  1. Write a program that prints a prompt then lets the user enter several numbers on the same line, with the numbers separated by spaces. When the user hits Enter your program should count and report how many of the numbers on the entered line are strictly above zero, below zero, or equal to zero. After this report, the user is given a new prompt and (s)he can enter a new line. The program ends when the user enters "quit" or enters an empty line.

  2. Write a program that prints a prompt then lets the user enter several numbers on the same line, with the numbers separated by spaces. When the user hits Enter your program should count and report how many of the numbers on the entered line are strictly greater than zero, and their average. (The numbers less than or equal to zero should not be included in the average). After this report, the user is given a new prompt and (s)he can enter a new line. The program ends when the user enters "quit" or enters an empty line.

  3. Write a program that prints a prompt then lets the user enter several numbers on the same line, with the numbers separated by spaces. When the user hits Enter your program should count and report how many of the numbers on the entered line are strictly less than zero, and their average. (The numbers that are greater than or equal to zero should not be included in the average). After this report, the user is given a new prompt and (s)he can enter a new line. The program ends when the user enters "quit" or enters an empty line.

  4. Write a program that prints a prompt then lets the user enter several numbers on the same line, with the numbers separated by spaces. When the user hits Enter your program should count and report how many of the numbers on the entered line are odd, and how many of them are even. It should also report the product of all the numbers on the line (both odd and even numbers are included in this product). After this report, the user is given a new prompt and (s)he can enter a new line. The program ends when the user enters "quit" or enters an empty line.

  5. Write a program that prints a prompt then lets the user enter several numbers on the same line, with the numbers separated by spaces. When the user hits Enter your program should count and report the product of all (strictly) negative numbers on the line, and the sum of all positive numbers on the line. If no negative numbers exist the program should say that, if no positive numbers exist the program should also say that. After this report, the user is given a new prompt and (s)he can enter a new line. The program ends when the user enters "quit" or enters an empty line.

  6. Write a program that prints a prompt then lets the user enter several numbers on the same line, with the numbers separated by spaces. When the user hits Enter your program should count and report the smallest negative number on the line. If no negative numbers are entered the program should print a message to that effect. After this report, the user is given a new prompt and (s)he can enter a new line. The program ends when the user enters "quit" or enters an empty line.

    Write a program that prints a prompt then lets the user enter several numbers on the same line, with the numbers separated by spaces. When the user hits Enter your program should count and report the largest positive number on the line. If no positive numbers are entered the program should print a message to that effect. After this report, the user is given a new prompt and (s)he can enter a new line. The program ends when the user enters "quit" or enters an empty line.

  7. Write a program that prints a prompt then lets the user enter several numbers on the same line, with the numbers separated by spaces. When the user hits Enter your program should count and report the sum of all numbers divided by their product. After this report, the user is given a new prompt and (s)he can enter a new line. The program ends when the user enters "quit" or enters an empty line.

  8. Write a program that prints a prompt then lets the user enter several numbers on the same line, with the numbers separated by spaces. When the user hits Enter your program should count and prints the same numbers in reverse order. Note that you don't need to print the numbers one by one, so you can easily use this code as a starting point:
    while (st.hasMoreTokens()) {
      a = a + st.nextToken(); 
    } 
    (That's like Four in Lecture Notes 13). Do you need to change anything to the code above ? After this report, the user is given a new prompt and (s)he can enter a new line. The program ends when the user enters "quit" or enters an empty line.

For the practical exam these questions were randomly distributed.

Each one of the test takers got one of these questions, at random.


Last updated: Mar 7, 2002 by Adrian German for A201