Question
If the sample code is needed, I can provide that a well. Method 1: public static boolean isPrime(int i) This method should return true if
If the sample code is needed, I can provide that a well.
Method 1: public static boolean isPrime(int i)
This method should return true if and only if the input i is a positive prime number. A prime is a number which is only divisible by 1 and itself (however the numbers 0 and 1 are not considered primes).
Method 2: public static int numPrimes(int lower, int upper)
This method will return the total number of primes in the range between lower and upper, including lower and upper themselves.
Hint: it's possible to use isPrime(int i) as part of the computation.
Method 3: public static int factorial(int n)
Find the factorial of n, which is given by n! = 1*2*...*(n-1)*n. The factorial of zero is a special case which is equal to 1.
Method 4: public static double sumPower(int n, double p)
Sums the series 1p+2p+...+(n-1)p+np.
Method 5: public static int boundedSum(int[] list, int low, int high)
Sums up the elements in list, but only including the elements x in list for which low x high.
Method 6: public static double filteredSum(double[] list, double[] filterList)
Assume that list and filterList are lists of the same length. Then if the elements in list are l0, l1, ..., ln-2, ln-1 and the elements in filterList are f0, f1, ..., fn-2, fn-1, then this method will returnl0f0+l1f1+...+ln-2fn-2+ln-1fn-1.
Method 7: public static double geometricMean(double[] list)
Computes the geometric mean of the numbers in list. If the n numbers in list are l0, l1, ..., ln-2, ln-1, then the geometric mean is defined as the nth root of the product l0l1...ln-2ln-1. You may assume that the list is not empty and the numbers are all positive.
Hint: you may use the built-in Math.pow().
Method 8: public static int largestConsecutiveDiff(int[] list)
Considering the set of differences between consecutive elements in list, this method returns the largest. Consecutive difference is defined as the latter element minus the earlier element, i.e. l1-l0. If there are not enough elements in the list to compute any differences, then the method should return zero by default.
Method 9: public static int largestElementWithDups(int[] list)
A duplicate element is an element which appears more than once in the list. This method returns the largest element in list which has any duplicates whatsoever. If none of the elements have duplicates (every element in the list is unique) then this method should return Integer.MIN_VALUE.
Method 10: public static void findElementFreqs(int[] list, int[] freqs)
Assume that list and freqs are lists of the same size. For each element in list, this method should count the number of times that elements occurs in the list, and store the value in the same spot in freqs.
For example, if list[3] == 4, and the number 4 appears a total of 7 times in list, then the value 7 should be stored in freqs[3]. The same goes for all elements in freqs
Most of the code isn't giving me difficulties, but I am coming into issues with answer Methods 8, 9, 10. I looked up help here and it is limited, and my Professor is not allowing the use of hashmaps. I don't know how to approach this.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started