View the step-by-step solution to:

Is there a way to reduce the number of lines of code?

Is there a way to reduce the number of lines of code?


package module2case;


import javax.swing.JOptionPane;


public class module4case {


   public static int[] performSort(int[] input) {


      for (int i = 0; i < input.length - 1; i++) {

         int index = i;

         for (int j = i + 1; j < input.length; j++)

            if (input[j] > input[index])

               index = j;


         int smallerNumber = input[index];

         input[index] = input[i];

         input[i] = smallerNumber;

      }

      return input;

   }


   public static void main(String a[]) {


      do {

         int[] input = new int[10];

         for (int i = 0; i < 10; i++) {

            input[i] = Integer.valueOf(JOptionPane.showInputDialog("Enter the number " + (i + 1) + ": "));

         }

         int[] output = performSort(input);

         String delimiter = "";

         String result = "The sorted result is: n";

         for (int i : output) {

            result += delimiter + i + " ";

            delimiter = ",";

         }

         JOptionPane.showMessageDialog(null, result);

         String s = JOptionPane.showInputDialog("Press E to exit the program or anything to continue: ");

         if ("E".equalsIgnoreCase(s)) {

            break;

         }


      } while (true);

   }

}


Top Answer

package module2case; import javax.swing.JOptionPane; import java.util.Arrays; import java.util.Collections; public class... View the full answer

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask a homework question - tutors are online