public class Test63{ public staticvoid main(String[] args) { int[] x1 = { 2, 8,
ID: 3614730 • Letter: P
Question
public class Test63{
public staticvoid main(String[] args) {
int[] x1 = { 2, 8, -34, 16, 4, 91, -6, 21};
int[] x2 = { -34, -6, 2, 4, 8, 16, 21,91};
// first call to method guessWhatIDo
boolean bv1 = guessWhatIDo(x1);
// second call to method guessWhatIDo
boolean bv2 = guessWhatIDo(x2);
// display the result
System.out.println("CMSC 130 - Homework 6- What is doing the method guessWhatIDo? ");
System.out.println("The result of calling guessWhatIDo method onarray x1 is: " + bv1);
System.out.println("The result of callingguessWhatIDo method on array x2 is: " + bv2);
}
public staticboolean guessWhatIDo(int[] a) {
boolean bRet = true;
for (int i = 0; i<a.length-1; i++){
if(a[i] >a[i+1]) {
bRet = false;
break;
}
}
return bRet;
}
}
Explanation / Answer
please rate - thanks the function compares each number in the array to the one next toit, check that the numbers in the array are in ascending order. If the numbers are in ascending order like array x2 it returns atrue if they are not in ascending order, like array x1, it returnsfalse
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.