The Question

Write a java program called Q2.java that will do the following: Write a program that prompts for and reads in a line of text and prints out the number of 'X's and the number of 'Z's in the input line. The output should be of the form

There are <#x> X's and <#z> Z's in the input line.

(Where <#x> is the number of X's and <#z> is the number of Z's)

The output should conform to that in the sample runs of a correct program shown below. Note that, in these sample runs, the % sign is not part of the output. User input is shown on the same line as the prompt.

Sample Runs

% java Q2
Enter a line of text ... HerXXXe is XZZ a liZZZne of X text
There are 5 X's and 5 Z's in the input line.
%
% java Q2
Enter a line of text ... A line withXXX only X's
There are 4 X's and 0 Z's in the input line.
%

Useful APIs

Here (again) are the common APIs that you may access:

Java 1.5 API
Type API

Submitting Your Work

Here is the command to submit your work (further details regarding the submit command can also be obtained by typing man submit
Once again, you are encouraged to submit regularly. Newer submissions overwrite older ones.

submit 1020 midtermW5 Q2.java