Question: Write a Java program called RecursiveMultiply.java that uses your method to compute the product of two input numbers. The input is two positive integers read
Write a Java program called RecursiveMultiply.java that uses your method to compute the product of two input numbers. The input is two positive integers read from the standard input, the first less than or equal to the second, and the output is the product. The output should be a number appearing on a line by itself. Your method should take int arguments, and return a long value.
For example, if the input is
15 20
then the output should be
300
Time your program on the input
20000000 20000000
/** Read two integers from standard input, * print out product. */ import java.util.Scanner; public class RecursiveMultiply { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int x = scan.nextInt(); int y = scan.nextInt(); long start = System.currentTimeMillis(); long z = mult(x,y); long t = System.currentTimeMillis() - start; System.out.println(z); // Use the following if you want to find run time. //System.out.println("Elapsed time = " + t); } public static long mult(int a, int b) { return (long) a*b; } } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
