Computer Program Reading Comprehension Project
U of T Computer Program Reading Comprehension Project
Half The Characters
Reads one line of input and prints every other character, starting with the first character.

Download files: HalfTheCharacters.java
Areas: User input and output.


HalfTheCharacters.java
1/*
2 *This was a program found on a midterm given out by Prof. Bellantoni at the
3 *University of Toronto for Fall 1998
4 */
5
6
7import java.io.*;
8
9public class HalfTheCharacters {
10   public static void main (String[] args) throws IOException {
Displaying 10 of 23 lines
View full source


Question 1
What is the purpose of the 'throws IOException' clause?
Hints Solution

Question 2
import java.io.*; imports every class found in the io package. However, only a few of the classes would need to be used. Write the import statements for these classes that would be used in lieu of the current import statement.
Hints Solution

Question 3
Under what conditions will this loop terminate? Do not just state the condition as written in the for-loop. Try to express it in plain English.
Hints Solution

Question 4
What are the possible values that i can have immediately after the last iteration of the loop?
Hints Solution

Question 5
What does i represent in this case?
Solution

Question 6
What is the purpose of InputStreamReader?
Solution

Question 7
Why is the InputStreamReader wrapped in a BufferedReader?
Solution

Question 8
If the input line is "Hello,World", what does the program print?
Solution

Question 9
If we initialized i to 1, would the name of the class still hold true? What would be the difference?
Hints Solution

Question 10
Reproduce the results of this program using a while loop instead of a for loop. You only have to produce the while loop that would be necessary. For the original program, why would the programmer choose a for loop instead of a while loop?
Hints Solution