import javax.swing.JOptionPane;
public class BubbleSort{
public static void main(String[] args){
int []arrayNumb = new int [10]; // Initialized arrayNumb to 10 elements
int counter = 0, counter2 = 0, counter3 = 0;
for(counter = 0; counter
String inputNumb = JOptionPane.showInputDialog(null, "Enter number:", "Input", JOptionPane.INFORMATION_MESSAGE);
int Numb = Integer.parseInt(inputNumb);
arrayNumb[counter] = Numb;
}
System.out.print("Unsorted Array : ");
for(int i = 0; i
System.out.print(arrayNumb[i] + ", ");
}
//This loop will now sort the numbers inputed above by the user using the bubble sort method.
for(counter2 = 0; counter2 IS LESSER THAN arrayNumb.length -1; ++counter2){
for(counter3 = 0; counter3 IS LESSER THAN arrayNumb.length -1; ++counter3){
if(arrayNumb[counter3] IS GREATER THAN arrayNumb[counter3+1]){
int temp = arrayNumb[counter3];
arrayNumb[counter3] = arrayNumb[counter3+1];
arrayNumb[counter3+1] = temp;
}
}
}
//Output the result.
System.out.print("\nSorted Array : ");
for(int i = 0; i
System.out.print(arrayNumb[i] + ",");
}
System.exit(0);
}
}
public class BubbleSort{
public static void main(String[] args){
int []arrayNumb = new int [10]; // Initialized arrayNumb to 10 elements
int counter = 0, counter2 = 0, counter3 = 0;
for(counter = 0; counter
String inputNumb = JOptionPane.showInputDialog(null, "Enter number:", "Input", JOptionPane.INFORMATION_MESSAGE);
int Numb = Integer.parseInt(inputNumb);
arrayNumb[counter] = Numb;
}
System.out.print("Unsorted Array : ");
for(int i = 0; i
}
//This loop will now sort the numbers inputed above by the user using the bubble sort method.
for(counter2 = 0; counter2 IS LESSER THAN arrayNumb.length -1; ++counter2){
for(counter3 = 0; counter3 IS LESSER THAN arrayNumb.length -1; ++counter3){
if(arrayNumb[counter3] IS GREATER THAN arrayNumb[counter3+1]){
int temp = arrayNumb[counter3];
arrayNumb[counter3] = arrayNumb[counter3+1];
arrayNumb[counter3+1] = temp;
}
}
}
//Output the result.
System.out.print("\nSorted Array : ");
for(int i = 0; i
}
System.exit(0);
}
}
Your thoughts about this post? Leave a commment now.