Write your name or username here: _______________________

Do this when you receive the paper.

Write a program that counts the number of times the word 'java' occurs in the input. Case sensitive comparison is used here. The input is a String (a line of text entered by the user). Feel free to use ConsoleReader to read lines from the user.

Here's how your program might work:

frilled.cs.indiana.edu%javac One.java
frilled.cs.indiana.edu%java One
Type> I am here.
The word java appears 0 times.
Type> I speak java. 
The word java appears 0 times.
Type> Java java java!
The word java appears 1 times.
Type> java java java to you too... 
The word java appears 3 times.
Type> done
frilled.cs.indiana.edu%
Feel free to use StringTokenizer to collect the words. When you're done turn the program in OnCourse under the Dropbox for the time and location of the exam even if you're from another section. Then write the program by hand on the back of this page and return it to the AI before you leave. I will grade this paper but I might refer to your posted code in OnCourse as well so please do both.

You can if you want turn in additional materials such as: pseudocode, flow charts, additional explanations of the code and/or the approach chosen. Be sure to solve as much as you can and to turn in a program in OnCourse at the end of the lab in addition to turning in the paper with your exam.

Good luck and do well.

import java.util.*; 

class One {
    public static void main(String[] args) {
	ConsoleReader c = new ConsoleReader(System.in); 
	String line; 
        System.out.print("Type> "); 
	line = c.readLine(); 
        while (! line.equals("done")) {
	    StringTokenizer st = new StringTokenizer(line); 
	    int number = 0; 
	    while (st.hasMoreTokens()) {
		String token = st.nextToken(); 
		if (token.equals("java")) {
		    number += 1; 
		} 
	    }
	    System.out.println("The word java appears " + number + " times."); 
	    System.out.print("Type> ");
	    line = c.readLine();
	}
    }
}