Practice Problems - Strings, Files, Parameters and Return Values


1. Write a method beginEnd() that takes a String and returns true if it begins and ends with the same character, and false otherwise. The method should return false if the String is the empty String.
Write a main method that:
a) Reads the name of an input file from the user
b) Prints the number of lines in the file that begin and end with the same character. Use your beginEnd() method.

2. Write a method gotCat() that takes a String, and returns true if the 3 middle symbols of the String are "cat" and false otherwise. Note that the method should return false if the String has even length.
Write a main method that:
Prints each line in the file dataFile.txt that contains "cat" as the middle 3 symbols.

3. Write a method compareA() that takes 2 Strings and returns true if they contain the same number of A's (upper or lower case) and false otherwise.

4. Write a method bigEven() that takes a String and returns the String with every other character capitalized (if it is a letter). For example:
bigEven("hello") --> "HeLlO"
bigEven("123me") --> "123mE"

5. Write every other line (starting with the first line) in the file Lines.txt to output file EveryOtherLine.txt.

6. Compute and print the average of all the floating point and integer tokens in the file nums.txt.