Question

Which of the following method headers could be used for a method that finds the largest...

Which of the following method headers could be used for a method that finds the largest value in an array of integers that is smaller than a given value? Mark ALL that apply.

public static int maxSmallerThan(int max, int[ ] arr)
public static int maxSmallerThan(int[ ] arr, int val)
public static int[ ] maxSmallerThan(int max, int answer)
public static void maxSmallerThan(int[ ] arr, int max, int answer)

Homework Answers

Answer #1

The answer to the above problem is as follows:

Option A - CORRECT - public static int maxSmallerThan(int max, int[ ] arr)
This is correct because the input parameters are the ones that would be correct, One parameter has to be the integer array as we need to find the largest in an array. And the other parameter has to the value which has to be compared to get the largest number in array smaller than this value. And the return type is also int, which is correct to return the largest value smaller than the given value.

Option B - CORRECT -public static int maxSmallerThan(int[ ] arr, int val)
Here also the input parameters are correct, and only the name is different which does not make a difference in terms of the result. Even the return type is correct. So its a correct option.

Option C - Wrong -public static int[ ] maxSmallerThan(int max, int answer)
This is wrong option because the input parameter does not have any array of integers. So without an array, how can we find the largest element in array. So its wrong here itself. And also the return type is set to an array of integers but we need to return an integer value. So wrong.

Option D - Wrong -public static void maxSmallerThan(int[ ] arr, int max, int answer)

This is wrong because the input parameter has three values but only two are required-one array of int and second an int value which would be reference point for largest value smaller than this. Nothing apart from these two is required, so its wrong. Also the return type is void which is wrong again.

Feel free to comment for any query.

Know the answer?
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
Similar Questions
JAVA please Arrays are a very powerful data structure with which you must become very familiar....
JAVA please Arrays are a very powerful data structure with which you must become very familiar. Arrays hold more than one object. The objects must be of the same type. If the array is an integer array then all the objects in the array must be integers. The object in the array is associated with an integer index which can be used to locate the object. The first object of the array has index 0. There are many problems where...
THIS IS JAVA PROGRAMMING Write a method that finds the shortest word in an array of...
THIS IS JAVA PROGRAMMING Write a method that finds the shortest word in an array of String values and returns the length, in characters, of that word. The method should use the following header. public static int minLength(String[] array) Write a test program that prompts the user to enter ten strings, store them in an array and invokes this method to return the shortest length, and displays that value. (A near complete program can be found attached to the dropbox)
IN JAVA!! You may be working with a programming language that has arrays, but not nodes....
IN JAVA!! You may be working with a programming language that has arrays, but not nodes. In this case you will need to save your BST in a two dimensional array. In this lab you will write a program to create a BST modelled as a two-dimensional array. The output from your program will be a two-dimensional array.   THEN: practice creating another array-based BST using integers of your choice. Once you have figured out your algorithm you will be able...
Using a loop, complete the following method so that it goes through the array from left...
Using a loop, complete the following method so that it goes through the array from left to right, one element at a time and replaces that element with the sum of itself and the next element in the array (if there is a next element). For example, if the input is {1, 3, 5} the output must be {4, 8, 5} -- on the first iteration 1 was replaced by 1+3; on the second iteration 3 was replaced by 3+5....
1.If you have defined a class,  SavingsAccount, with a public  static method,  getNumberOfAccounts, and created a  SavingsAccount object referenced by...
1.If you have defined a class,  SavingsAccount, with a public  static method,  getNumberOfAccounts, and created a  SavingsAccount object referenced by the variable  account20, which of the following will call the  getNumberOfAccounts method? a. account20.getNumberOfAccounts(); b. SavingsAccount.account20.getNumberOfAccounts(); c. SavingsAccount.getNumberOfAccounts(); d. getNumberOfAccounts(); e. a & c f. a & b 2.In the following class, which variables can the method printStats use? (Mark all that apply.) public class Item { public static int amount = 0; private int quantity; private String name; public Item(String inName, int inQty) { name...
Write code in java Implement a method to build an AVL tree out of a sorted...
Write code in java Implement a method to build an AVL tree out of a sorted (ascending order) array of unique integers, with the fastest possible big O running time. You may implement private helper methods as necessary. If your code builds a tree that is other than an AVL tree, you will not get any credit. If your code builds an AVL tree, but is not the fastest big O implementation, you will get at most 12 points. You...
What output do we get? How do we get that output? Consider the following method :...
What output do we get? How do we get that output? Consider the following method : public static void processArray (int [] array) { int x = 0; for (int i = 0; i < array.length - 1; i++ ) { if (array [i] < array [i+1]) { System.out.println (i + 1) ;         }     } } In the left-hand column below are specific arrays of integers. Indicate in the right- hand column what value would be printed by...
Write a method name maxElement, which returns the largest value in an array that is passed...
Write a method name maxElement, which returns the largest value in an array that is passed as an argument. The method must use recursion to find the largest element. Demonstrate the method in a program. Write the JAVA CODE on the paper that is provided. (Put your name on every piece of paper) Use the following array to test the method. Int [] numbers = {2,12,1999,99,100,4,7,300} PROGRAMMING LANGUAGE- JAVA. Please answer the question ASAP. Thanks in advance!
I was proud that I figured out the answer myself but then I read the question...
I was proud that I figured out the answer myself but then I read the question again and noticed the signature: Write a method findDuplicates that will return an array consisting of all duplicate values that were found in a given array. For example, if given an array consisting of the values {1, 7, 3, 7, 3, 4, 1, 3, 2} the method would return an array consisting of the values {1,7,3}.           public static int[] findDuplicates(int[] naVals) What I...
Objectives:The focus of this assignment is to create and use a recursive method given a moderately...
Objectives:The focus of this assignment is to create and use a recursive method given a moderately difficult problem. Program Description: This project will alter the EmployeeManager to add a search feature, allowing the user to find an Employee by a substring of their name. This will be done by implementing the Rabin-Karp algorithm. A total of seven classes are required. Employee (From previous assignment) HourlyEmployee (From previous assignment) SalaryEmployee (From previous assignment) CommissionEmployee (From previous assignment) EmployeeManager (Altered from previous...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT