Demonstrate the ability to
u:\lab8\ with one Java code files: Driver.java.Based on Chapter 12, Programming Challenges 1 (Recursive Multiplication), 7 (Recursive Power Method), and 8 (Sum of Numbers).
Create a new Lab 8 project and copy and paste the code below into your Driver class. Complete the recursive methods multiply, power, and sumOfNumbers
import java.util.Scanner;
public class Driver
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
System.out.print("Recursive Multiplication - Enter two numbers: ");
int x = keyboard.nextInt();
int y = keyboard.nextInt();
System.out.println(x + " times " + y +
" equals " + multiply(x, y));
System.out.print("\nRecursive power - Enter two numbers: ");
x = keyboard.nextInt();
y = keyboard.nextInt();
System.out.println(x + " raised to the power of " + y +
" is " + power(x, y));
System.out.print("\nSum of Numbers - Enter a number: ");
int number = keyboard.nextInt();
System.out.println("The sum of the integers 1 through "
+ number + " is " + sumOfNumbers(number));
}
public static double multiply(double x, double y)
{
}
public static double power(double x, double y)
{
}
public static int sumOfNumbers(int max)
{
}
}
Recursive Multiplication - Enter two numbers:5 35 times 3 equals 15.0 Recursive power - Enter two numbers:2 42 raised to the power of 4 is 16.0 Sum of Numbers - Enter a number:6The sum of the integers 1 through 6 is 21
If you finish early, get yourself checked off first! As a programming challenge (not required but recommended):
Do Programming Challenge 9 (Ackermann's Function) as well
ackermann(0, 0) = 1 ackermann(0, 1) = 2 ackermann(1, 1) = 3 ackermann(1, 2) = 4 ackermann(1, 3) = 5 ackermann(2, 2) = 7 ackermann(3, 2) = 29