Classes to write for the programming part
Class | Description |
Reversers | You will write two functions to create reversed strings. The first,
called reverseLine(), will return a string with
all of the characters reversed. The second, reverseWords(), will
return a string with the
characters of each "word" reversed, but the order in which the words
come in the line is the same as the original. By "word" here, we
mean a sequence of characters with no spaces. You can assume there
is exactly one space between each pair of words. You may want to use
String.split( )or the StringTokenizer class to pick out
the words. For example, if an input string, str, is:The 'words' can contain punctuation. then reverseLine(str) returns .noitautcnup niatnoc nac 'sdrow' ehT And reverseWords(str) returns ehT 'sdrow' nac niatnoc .noitautcnup |
Sieve | The Sieve of Eratosthenes is a famous way of finding all prime
numbers in a range reasonably efficiently. It has been known for a
couple of millennia. A prime number is an integer that is
greater than 1 and has no positive integer factors besides 1 and itself.
You are to write a single method, sieve(lower, upper), that takes two positive integers,
the first one smaller than the second one. Your program is to
return a string (with a single space after each
number, including the last one to make it easier) containing all prime numbers that are in the closed interval bounded by
these two numbers. For example, if the arguments are
53 103 , then the string returned should be:"53 59 61 67 71 73 79 83 89 97 101 103 "
For another example, if the command-line arguments are 10000000 10000200 , then the string should be:"10000019 10000079 10000103 10000121 10000139 10000141 10000169 10000189
" Here is how the algorithm works, assuming that the two numbers are lower and upper.
Hint: your inner loop should not have division, multiplication, or %, in order not to slow things down! |