Untitled Document
Here are some practice programs for working with Strings and Arrays.
- Write a program that reads in a list of names, stores then in an array,
then prints out the list.
- Modify program (1) to have a search method that takes a name and searches
through the list for it. This should either print the index where the name
is stored in the list, or else a message saying that the name is not in the
list.
- Add to program (1) a method that looks through the list and prints the longest
name in the list.
- Write a new version of the prime number generator (say a program that prints
the first n primes). This time you should store the prime numbers in an array
as you find them. To determine if a number is prime you only need to divide
the primes numbers less or equal to the square root of the number. If none
of these divide evenly, the number is prime.
- Write a program that reads in strings and reports whether they are palindromes (strings that read the same forwards and backwards, like "bob" or "anna". Be sure that your program can handle both even-length and odd-length palindromes.