3 Replies Latest reply: Jun 14, 2013 3:18 AM by jwenting RSS

    Difficulty Understanding Code

    999443
      The following is a block of code from a book. It is part of an alphabetization program for a string of words in a paragraph earlier in the program. I get how the program works but I don't understand the following:

      // Sort the array of words
      String temp = null;
      boolean exchange = true;
      while(exchange) {
      exchange = false;
      for(int i = 1 ; i < words.length ; ++i) {
      if(words[i-1].compareTo(words) > 0) {
      temp = words[i];
      words[i] = words[i-1];
      words[i-1] = temp;
      exchange = true;
      }
      }
      }

      // If exchange is set to false then does the rest of the code block execute?

      Edited by: 996440 on Apr 20, 2013 1:06 PM