created 01/01/03
Write a program that implements this definition of cube numbers:
cube(1) = 1 cube(N) = cube(N-1) + 3(square(N)) - 3N + 1
Implement the square()
method using this definition
(also given in the exercises for chapter 71):
square(1) = 1 square(N) = square(N-1) + 2N - 1
Make a complete program similar to PyramidTester.java given in the chapter.
Click here to go back to the main menu.
Consider this definition of the sum of the elements in an integer array:
sum( array, index ) = 0, if index == array.length sum( array, index ) = array[index] + sum( array, index+1), if index < array.length
Write a Java method that implements this definition and a program to test it. The method should look something like:
int sum ( int[] array, int index ) { . . . }
The testing program will call sum( testArray, 0 )
Click here to go back to the main menu.
Improve the previous program by extending the definition of sum
:
sum( array ) = sum( array, 0 ) sum( array, index ) = 0, if index == array.length sum( array, index ) = array[index] + sum( array, index+1), if index < array.length
To implement this, write a second method sum( int[] array)
sum( testArray )
Click here to go back to the main menu.
Write your own recursive definition of the maximum element in an array of integers. Then, implement your definition in Java and test it with a testing program.
Click here to go back to the main menu.
A palindrome is a string that is the same when reversed. For example, "abba" is a palindrome. Here is a math-like definition:
palindrome( "" ) = true palindrome( x ) = true palindrome( x+X+y ) = false, if x != y = palindrome( X ), if x == y
The symbol x
stands for a single character,
as does y
.
The symbol X
stands for a string of characters.
The symbol +
stands for concatenation.
Implement palindrome()
and a program that tests it.
Click here to go back to the main menu.