1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
valentina_108 [34]
2 years ago
10

Product with recursive methods using recursion, create a program that will allow for a user to enter 5 numbers. The program will

provide the product of all 5 numbers using recursive methods. Submit screenshots of your program?s execution and output. Include all appropriate source code in a zip file. Java.
Computers and Technology
1 answer:
MrRa [10]2 years ago
5 0

Given a product with recursive methods using recursion, the program that will allow for a user to enter 5 numbers is given below.

<h3>What program will allow for a user to enter 5 numbers is given below?</h3>

import java.util.Scanner;

class Main

{

public static void main(String[] args)

{

int[] arrray = new int[5]; // variable declaration

Scanner s = new Scanner(System.in); // scanner declaration

System.out.print("Enter five numbers:");

for(int i=0;i<5;i++)  // Loop runs from 0 to 4 total 5 times

arrray[i] = s.nextInt();   // Accept array elements

System.out.println("Multiplication of 5 numbers is "+multiply(arrray,4));  // calling function

}

public static int multiply(int x[], int count)  // Called function

{

if(count<0)

return 1;  // It return 1

return x[count] * multiply(x, --count);  // recursive calling

}

}

Learn more about programs:
brainly.com/question/26134656
#SPJ1

You might be interested in
We can save our data peremently on a
riadik2000 [5.3K]

Answer:

modem

Explanation:

hope it helps

4 0
3 years ago
Read 2 more answers
If a while loop iterates forever,what is the most likely cause?
miv72 [106K]

Answer:

Runtime error probably. The program won't make it past the while loop in the code.

5 0
2 years ago
Why do many experts recommand longer time horizonal if you are doing high risk investment
Lapatulllka [165]

Answer:In general, the longer your time horizon, the better you can handle fluctuations in value and take more risk in order to reap greater rewards.

Explanation:

5 0
3 years ago
An interface that doesn’t contain any constants or methods is called a ____________ interface.
valina [46]
I dont under stand but i think it is a "plane"

4 0
4 years ago
Implement a method called bubbleSort, that takes an ArrayList, sorts it using bubble sort algorithm, and returns a sorted list;
boyakko [2]

Answer:

Java algorithm is given below

Explanation:

import java.util.ArrayList;

import java.util.Arrays;

import java.util.Random;

public class Temp {

   static void bubbleSort(ArrayList<Integer> list) {

       int n = list.size();

       for (int p = 0; p < n - 1; p++)

           for (int q = 0; q < n - p - 1; q++)

               if (list.get(q) > list.get(q + 1)) {

                   int temp = list.get(q);

                   list.set(q, list.get(q + 1));

                   list.set(q + 1, temp);

               }

   }

   static void selectionSort(ArrayList<Integer> list) {

       int n = list.size();

       for (int p = 0; p < n - 1; p++) {

           int minimumIndex = p;

           for (int q = p + 1; q < n; q++)

               if (list.get(q) < list.get(minimumIndex))

                   minimumIndex = q;

           int temp = list.get(p);

           list.set(p, list.get(minimumIndex));

           list.set(minimumIndex, temp);

       }

   }

   static void insertionSort(ArrayList<Integer> list) {

       int size = list.size();

       int p, val, q;

       for (p = 1; p < size; p++) {

           val = list.get(p);

           q = p - 1;

           while (q >= 0 && list.get(q) > val) {

               list.set(q + 1, list.get(q));

               q = q - 1;

           }

           list.set(q + 1, val);

       }

   }

   static void mergeSort(ArrayList<Integer> list, int low, int high) {

       if (low < high && (high - low) >= 1) {

           int mid = (high + low) / 2;

           mergeSort(list, low, mid);

           mergeSort(list, mid + 1, high);

           merger(list, low, mid, high);

       }

   }

   static void merger(ArrayList<Integer> list, int low, int mid, int high) {

       ArrayList<Integer> mergedArray = new ArrayList<Integer>();

       int left = low;

       int right = mid + 1;

       while (left <= mid && right <= high) {

           if (list.get(left) <= list.get(right)) {

               mergedArray.add(list.get(left));

               left++;

           } else {

               mergedArray.add(list.get(right));

               right++;

           }

       }

       while (left <= mid) {

           mergedArray.add(list.get(left));

           left++;

       }

       while (right <= high) {

           mergedArray.add(list.get(right));

           right++;

       }

       int i = 0;

       int j = low;

       while (i < mergedArray.size()) {

           list.set(j, mergedArray.get(i++));

           j++;

       }

   }

   public static void main(String[] args) throws Exception {

       ArrayList<Integer> list = new ArrayList<>();

       Random rand = new Random(System.currentTimeMillis());

       for (int i = 0; i < 10000; i++) {

           list.add(rand.nextInt(256));

       }

       long start = System.currentTimeMillis();

       selectionSort(list);

       int sel = (int) (System.currentTimeMillis() - start);

       System.out.println("Selection Sort time (in ms): " + sel);

       list.clear();

       // ------------------------

       rand = new Random(System.currentTimeMillis());

       for (int i = 0; i < 10000; i++) {

           list.add(rand.nextInt(256));

       }

       start = System.currentTimeMillis();

       insertionSort(list);

       int ins = (int) (System.currentTimeMillis() - start);

       System.out.println("Insertion Sort time (in ms): " + ins);

       list.clear();

       // ------------------------

       rand = new Random(System.currentTimeMillis());

       for (int i = 0; i < 10000; i++) {

           list.add(rand.nextInt(256));

       }

       start = System.currentTimeMillis();

       bubbleSort(list);

       int bub = (int) (System.currentTimeMillis() - start);

       System.out.println("Bubble Sort time (in ms): " + bub);

       list.clear();

       // ---------------------------

       rand = new Random(System.currentTimeMillis());

       for (int i = 0; i < 10000; i++) {

           list.add(rand.nextInt(256));

       }

       start = System.currentTimeMillis();

       mergeSort(list, 0, list.size() - 1);

       int mer = (int) (System.currentTimeMillis() - start);

       System.out.println("Merge Sort time (in ms): " + mer);

       long m = Math.min(Math.min(sel, ins), Math.min(bub, mer));

       if (m == sel)

           System.out.println("Selection Sort is fastest");

       else if (m == ins)

           System.out.println("insertion Sort is fastest");

       else if (mer == m)

           System.out.println("Merge Sort is fastest");

       else if (m == bub)

           System.out.println("Bubble Sort is fastest");

   }

}

6 0
3 years ago
Other questions:
  • Given the following stream of accesses to a 4-block fully associative cache with LRU replacement, determine whether the access i
    8·1 answer
  • What is a basic operation of computers
    13·1 answer
  • What is not true about contracts?
    12·2 answers
  • In the context of wireless signal propagation, the phenomenon that occurs when an electromagnetic wave encounters an obstruction
    14·1 answer
  • Malware is a combination of which two words? A. malevolent and software B. malignant and software C. maladapted and software D.
    8·1 answer
  • True or False:<br><br> You can convert your PowerPoint presentation in web pages.
    8·2 answers
  • Which element can be changed using the Print pane? Check all that apply
    9·1 answer
  • What is folded card publishing?​
    5·2 answers
  • The number of distinct proper subsets of a set with n elements is.
    13·1 answer
  • assuming the default gateway is connected to the internet, what type of internet access would this server have?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!