Personal tools
You are here: Home Classes Fall 2004 - Spring 2005 CS 150 Untitled Document
Document Actions

Untitled Document

by admin last modified 2005-05-11 13:30

Here are some practice programs for working with Strings and Arrays.

  1. Write a program that reads in a list of names, stores then in an array, then prints out the list.
  2. 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.
  3. Add to program (1) a method that looks through the list and prints the longest name in the list.
  4. 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.
  5. 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.
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: