Hi all...I have this program here
import javax.swing.JOptionPane; public class BubbleSort { public static void main(String[] args) { double[] list = new double[10]; bubbleSort(list); JOptionPane.showMessageDialog(null, "Thanks for playing!"); } //The Method for sorting the numbers public static void bubbleSort(double[] list) { //Declare variables double currentMin; int currentMinIndex, i, j; //Store user input for (i = 0; i < list.length; i++) list[i] = Double.parseDouble(JOptionPane.showInputDialog(null, "Enter next numbers.")); //Print the numbers entered JOptionPane.showMessageDialog(null, "The numbers you entered were: \n" + list[0] + " " + list[1] + " " + list[2] + " " + list[3] + " " + list[4] + " " + list[5] + " " + list[6] + " " + list[7] + " " + list[8] + " " + list[9]); JOptionPane.showMessageDialog(null, "The numbers will now swap till they are sorted from low to high: "); for (i = 0; i < list.length - 1; i++) { //Find the minimum in the list currentMin = list[i]; currentMinIndex = i; for (j = i + 1; j < list.length; j++) { if (currentMin > list[j]) { currentMin = list[j]; currentMinIndex = j; } } //Swap list[i] with list[currentMinIndex] if necessary if (currentMinIndex != i) { list[currentMinIndex] = list[i]; list[i] = currentMin; //Print the sorted numbers JOptionPane.showMessageDialog(null, list[0] + " " + list[1] + " " + list[2] + " " + list[3] + " " + list[4] + " " + list[5] + " " + list[6] + " " + list[7] + " " + list[8] + " " + list[9]); } } } }
While my teacher gave this assignment an A, he wants me to get rid of this type of code...
JOptionPane.showMessageDialog(null, "The numbers you entered were: \n" + list[0] + " " + list[1] + " " + list[2] + " " + list[3] + " " + list[4] + " " + list[5] + " " + list[6] + " " + list[7] + " " + list[8] + " " + list[9]);
He hinted at the += style using a string. Does anyone know what he's talking about?
Neil