Java Reference
In-Depth Information
For example,
reverseDisplay("abcd")
displays
dcba
. Write a test program
that prompts the user to enter a string and displays its reversal.
*18.10
(
Occurrences of a specified character in a string
) Write a recursive method that
finds the number of occurrences of a specified letter in a string using the follow-
ing method header:
public static int
count(String str,
char
a)
For example,
count("Welcome", 'e')
returns
2
. Write a test program that
prompts the user to enter a string and a character, and displays the number of
occurrences for the character in the string.
*18.11
(
Sum the digits in an integer using recursion
) Write a recursive method that
computes the sum of the digits in an integer. Use the following method header:
public static int
sumDigits(
long
n)
+
+
=
For example,
sumDigits(234)
returns 2
9. Write a test program
that prompts the user to enter an integer and displays its sum.
3
4
Section 18.5
**18.12
(
Print the characters in a string reversely
) Rewrite Programming Exercise 18.9
using a helper method to pass the substring
high
index to the method. The
helper method header is:
public static void
reverseDisplay(String value,
int
high)
*18.13
(
Find the largest number in an array
) Write a recursive method that returns the
largest integer in an array. Write a test program that prompts the user to enter a
list of eight integers and displays the largest element.
*18.14
(
Find the number of uppercase letters in a string
) Write a recursive method
to return the number of uppercase letters in a string. Write a test program that
prompts the user to enter a string and displays the number of uppercase letters in
the string.
*18.15
(
Occurrences of a specified character in a string
) Rewrite Programming Exer-
cise 18.10 using a helper method to pass the substring
high
index to the method.
The helper method header is:
public static int
count(String str,
char
a,
int
high)
*18.16
(
Find the number of uppercase letters in an array
) Write a recursive method
to return the number of uppercase letters in an array of characters. You need to
define the following two methods. The second one is a recursive helper method.
public static int
count(
char
[] chars)
public static int
count(
char
[] chars,
int
high)
Write a test program that prompts the user to enter a list of characters in one line
and displays the number of uppercase letters in the list.
*18.17
(
Occurrences of a specified character in an array
) Write a recursive method that
finds the number of occurrences of a specified character in an array. You need to
define the following two methods. The second one is a recursive helper method.
public static int
count(
char
[] chars,
char
ch)
public static int
count(
char
[] chars,
char
ch,
int
high)
Search WWH ::
Custom Search