Java Reference
In-Depth Information
eXerCISeS 5
1.
Write an iterative function to return the n th Fibonacci number.
2.
print an integer with commas separating the thousands. For example, given 12058, print 12,058.
3. A is an array containing n integers. Write a recursive function to find the number of times a
given integer x appears in A .
4.
Write a recursive function to implement selection sort .
5.
Write a recursive function to return the largest element in an integer array.
6.
Write a recursive function to search for a given number in an int array.
7.
Write a recursive function to search for a given number in a sorted int array.
8.
What output is produced by the call W(0) of the following function?
public static void W(int n) {
System.out.printf("%3d", n);
if (n < 10) W(n + 3);
System.out.printf("%3d", n);
}
9.
What output is produced by the call S('C') of the following function?
public static void S(char ch) {
if (ch < 'H') {
S(++ch);
System.out.printf("%c ", ch);
}
}
10.
in 9, what output would be produced if the statements within the if statement are
interchanged?
11.
in 9, what would happen if ++ch is changed to ch++ ?
12.
Write a recursive function, length , that, given a pointer to a linked list, returns the number of
nodes in the list.
13.
Write a recursive function, sum , that, given a pointer to a linked list of integers, returns the
sum of the values at the nodes of the list.
14.
Write a recursive function that, given a pointer to the head of a linked list of integers, returns
true if the list is in ascending order and false if it is not.
15.
Write a recursive method that takes an integer argument and prints the integer with one
space after each digit. For example, given 7583 , it prints 7 5 8 3 .
16.
What is printed by the call fun(18, 3) of the following recursive function?
Search WWH ::




Custom Search