CSC 120

Week 7


Sample Programs:

Here are some of the sample programs, and more, we looked at in class: BinarySearch.java CountWord.java ArrayListSum.java numbers.txt FindWord.java words.txt CommandLine.java CommandLine2.java

To do:

Finish reading Chapter 5. Go over the practice midterm exam in the lab.

Lab/Homework Assignment:


  1. Write a program that asks the user to type her name. Load the line into a char array. Then print the name, and print the name in reverse. (Hint: Examine the code CountWord.java.)

  2. Add to the program above to test if the user's name is a palindrome, that is, if the name spells the same forward and backward. Your test should ignore cases; you can do this by converting the string containing the name using the toLowerCase() string method which return the lower case of the string. e.g. name = name.toLowerCase() . Your code should include a method
    public static boolean isPalindrome( char[] buffer)
    Examples of palindomes:
    ANNA
    Anna
    Tim Mit