
Concept explainers
For each part below, fill in the table to trace the values as they are passed from main and changed in the method.
a.
int [] array = {1,2,3,4,5};
int x = 12;
int y = doOne(array,x);
int [ ] array2 = {1,2,3,4,5};
int w = doOne(array2, array2[3]);
} // end of main
public static int doOne(int[] arr, int x){
for (int i=0; i<arr.length-1; i++)
arr[i] = arr[i]*arr[i+1];
x = x+3;
return x;
}
x in main before call to doOne
|
|
array in main before call to doOne
|
|
arr in doOne before loop
|
|
x in doOne before loop
|
|
arr in doOne after loop
|
|
x in doOne after loop
|
|
x in main after call to doOne
|
|
y in main after call to doOne
|
|
array in main after call to doOne
|
|
array2 in main before call to doOne
|
|
arr in doOne before loop
|
|
x in doOne before loop
|
|
arr in doOne after loop
|
|
x in doOne after loop
|
|
w in main after call to doOne
|
|
array2 in main after call to doOne
|
|
b.
int [] array3 = {1,2,3,4,5};
int s = 12;
int v = 32;
int [] num = doTwo(array3, v,s);
} // end of main
public static int[] doTwo(int[] arr, int x, int y){
int[] ret = new int[2];
x = arr[2] ;
y = arr[3] ;
ret[0] = x+arr[1];
ret[1] = y-arr[0];
return ret;
}
array3 before call to doTwo
|
|
s before call to doTwo
|
|
v before call to doTwo
|
|
arr in doTwo
|
|
x in doTwo
|
|
y in doTwo
|
|
ret in doTwo
|
|
array3 in main after call to doTwo
|
|
num in main after call to doTwo
|
|
s in main after call to doTwo
|
|
v in main after call to doTwo:
|
|

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

- public int binarySearch(int[]array, int num) {int low = 0;//low rangeint high = array.length -1; //high range int mid; //mid rangewhile () //while low is less than or equal to high{mid = ; //set middle range to be (low + high) /2if () { //if the array in the middle range = input number//return mid range }elseif () { //if the array in the middle range > input number//set the high value to be the mid value minus 1 }else{//set low value to be mid value plus one } }//return -1 here because that would mean that the number is not found in the loop}arrow_forwardHow do you initialize an array in C?a) int arr[3] = (1,2,3);b) int arr(3) = {1,2,3};c) int arr[3] = {1,2,3};d) int arr(3) = (1,2,3);arrow_forwardMethod Details getCountInRange public static int getCountInRange(int[] array, int lower, int upper) Returns the number of values in the range defined by lower (inclusive) and upper (inclusive) Parameters: array - integer array lower - lower limit upper - upper limit Returns: Number of values found Throws: java.lang.IllegalArgumentException - if array is null or lower is greater than upper Any error message is fine (e.g., "Invalid parameters(s)")arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





