Question

Programming 3_4: Write the method public static int rangeProduct(int a, int b). Assume that a <...

Programming 3_4: Write the method public static int rangeProduct(int a, int b). Assume that a < b. Your method must compute and return the product of the integers in the range from a to b. For example, if a = 3 and b = 6, your method would compute and return the product 3 × 4 × 5 × 6 = 360. public static int rangeProduct(int a, int b) {...}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

   public static int rangeProduct(int a, int b)
    {
        int prod=1;
        for(int i=a;i<=b;i++)
        {
            prod*=i;
        }
        return prod;
    }
   

Add a comment
Know the answer?
Add Answer to:
Programming 3_4: Write the method public static int rangeProduct(int a, int b). Assume that a <...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please Help! Need in Java C++ Object oriented programming. Thank you! Method 2: public static int...

    Please Help! Need in Java C++ Object oriented programming. Thank you! Method 2: public static int sumCapped(int[] nums, int x) This method will return the largest sum that is less than or equal x found in one pass of the array. This means that you must check each number in succession to determine whether or not you should add it in. For example, for the array {4, 2, 3, 5} with the value of the paramter x set to 7,...

  • 1. Write a complete program based on public static int lastIndexOf (int[] array, int value) {...

    1. Write a complete program based on public static int lastIndexOf (int[] array, int value) { for (int i = array.length - 1; i >= 0; i--) { if (array [i] == value) { return i; } } return -1; write a method called lastindexof that accepts an array of integers and an integer value as its parameters and returns the last index at which the value occurs in the array. the method should return -1 if the value is...

  • Write a public static method named getMaxOf2Ints that takes in 2 int arguments and returns the...

    Write a public static method named getMaxOf2Ints that takes in 2 int arguments and returns the Maximum of the 2 values Write a public static method named getMinOf2Ints that takes in 2 int arguments and returns the Minimum of the 2 values Write apublic static method named getMaxOf3Ints that takes in 3 int arguments and returns the Maximum of the 3 values Write a public static method named getMedianOf3Ints that takes in 3 int arguments and returns the Median Value...

  • JAVA 1.Write a static method named getMaxEven(numbers) which takes an array of positive integers as a...

    JAVA 1.Write a static method named getMaxEven(numbers) which takes an array of positive integers as a parameter. This method calculates and returns the largest even number in the list. If there are no even numbers in the array, the method should return 0. You can assume that the array is not empty. For example: Test Result int[] values = {1, 4, 5, 9}; System.out.println(getMaxEven(values)); 4 System.out.println(getMaxEven(new int[]{1, 3, 5, 9})); 0 public static int --------------------------------------------------------------------------------- 2. Write a static method...

  • Write a method public static boolean FindSum (int[] a, int m) that takes an ascending sorted...

    Write a method public static boolean FindSum (int[] a, int m) that takes an ascending sorted array a with n distinct integers, and an integer m. If there are two elements in the array that add to be m, the method returns True; if not, it returns False. You may assume that the elements in the array are all distinct. There are several ways to solve this problem! (and some solutions are worth more points than others!) For 6 points,...

  • static public int[] Question() // retrieve an integer 'n' from the console // the first input...

    static public int[] Question() // retrieve an integer 'n' from the console // the first input WILL be a valid integer, for 'n' only. // then read in a further 'n' integers into an array. // in the case of bad values, ignore them, and continue reading // values until enough integers have been read. // this question should never print "Bad Input" like in lab // hint: make subfunctions to reduce your code complexity return null; static public int...

  • You will implement the following method public static int[] linearSearchExtended(int[][] numbers, int key) { // Implement...

    You will implement the following method public static int[] linearSearchExtended(int[][] numbers, int key) { // Implement this method return new int[] {}; }    There is a utility method provided for you with the following signature. You may use this method to convert a list of integers into an array. public static int[] convertIntegers(List<Integer> integers) Provided code import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Scanner; public class MatrixSearch { // This method converts a list of integers to an array...

  • Submit Chapter7.java with four (4) public static methods as follows: A. Write a method called mostCommon...

    Submit Chapter7.java with four (4) public static methods as follows: A. Write a method called mostCommon that accepts an array of integers as its only parameter, and returns the int that occurs most frequently. Break ties by returning the lower value For example, {1,2,2,3,4,4} would return 2 as the most common int. B. Write mostCommon (same as above) that accepts an array of doubles, and returns the double that occurs most frequently. Consider any double values that are within 0.1%...

  • must provide the following public interface: public static void insertSort(int [] arr); public static void selectSort(int...

    must provide the following public interface: public static void insertSort(int [] arr); public static void selectSort(int [] arr); public static void quickSort(int [] arr); public static void mergeSort(int [] arr); The quick sort and merge sort must be implemented by using recursive thinking. So the students may provide the following private static methods: //merge method //merge two sorted portions of given array arr, namely, from start to middle //and from middle + 1 to end into one sorted portion, namely,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT