Q BgQuestion:

      
Novice
Karma Points: 37
Respect (79%):
posted by  Al3x 84 on 11/4/2009 8:49:03 PM  |  status: Closed  |  Earned Karma: 37

Java Program

Course Textbook Chapter Problem Needs by
N/A N/A N/A N/A 11/4/2009 at 10:00:00 PM
Question Details:
Explain what is testing the method guessWhatIDo from the following program:

public class Test63 {

   public static void 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?\n");

     System.out.println("The result of calling guessWhatIDo method on array x1 is: " + bv1);
     System.out.println("The result of calling guessWhatIDo method on array x2 is: " + bv2);
  }

  public static boolean 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;
  }

}

Bonus Point Alert! Earn +7 additional karma points for helping this gold member.

AAnswers:

Answer Question Ask for clarification
Oracle
Karma Points: 31,937
posted by rapunzel on 11/4/2009 9:45:02 PM  |  status: Live
Asker's Rating: Lifesaver   
Response Details:
please rate - thanks

the function compares each number in the array to the one next to it, check that the numbers in the array are in ascending order.

If the numbers are in ascending order like array x2 it returns a true
if they are not in ascending order, like array x1, it returns false


Note to all members 1. Please 1 question per post 2. Show respect to your fellow members by rating all answers. 3. When rating remember that the first answer is not necessarily the best answer. 4. When answering questions, explain what you are doing, so that the asker will learn, don't just give a meaningless number. 5. Your answers should be your work. Don't copy from another member, this is Karma abuse and possible disciplinary actions against you. and GOOD LUCK to you all!!
Answer Question Ask for clarificarion

Join Cramster's Community

Cramster.com brings together students, educators and subject enthusiasts in an online study community. With around-the-clock expert help and a community of over 100,000 knowledgeable members, you can find the help you need, whenever you need it. Join for free today » How Cramster is different from tutoring »