|
|
|
|
Access the course homepage at:
http:www.cis.udel.edu/~caviness/java/course_hp.html
Follow the links to find,
copy, compile, and execute one of the example programs.
|
|
Alter the Fibonacci program to mark each number as prime or
composite as is appropriate. Do this by writing a method
public static boolean isPrime( int n ) that
returns true if n is prime and false otherwise. You may
have to rely (just a little bit) on your knowledge of C. The
following may be useful:
|
|
|
System.out.print() works just like
System.out.println() except that it does not insert
a new line character at the end of the output.
|
|
|
To make isPrime() faster, try using the static
method
Math.sqrt( double ) from the class Math.
Static methods from another class are called by prefixing
their name with the class name as show above. Static
methods defined in the same class are called just like they
are in C/C++.
|
|
Alter the character count program to emulate the Unix
command wc. That is, print three numbers: the number
of lines, the number of words, and the number of characters
in the file. Follow the three numbers by the name of the
file that is given on the command line, if there is one.
Some potentially useful info:
|
|
|
Recall that '\n' is the new line character.
|
|
|
System.out.println() without any args simply
inserts a new line character in the out stream.
|