User:MFaroukAli/sandbox

import javax.swing.JOptionPane; import java.util.Arrays; public class Sorting{ public static void main (String [] args){

int arraySize; String choice,order; boolean doMore = true; arraySize = Integer.parseInt(JOptionPane.showInputDialog("Input the size of your array: ")); int array[] = new int [arraySize]; int array2[] = new int[arraySize];

for(int i = 0,j=1;i<array.length;i++,j++) array[i] = Integer.parseInt(JOptionPane.showInputDialog("Input value for the array: " + j+"/"+arraySize));

choice = JOptionPane.showInputDialog("Choose a Sorting Algorithm to perfrom: " +                                             "\nB - Bubble Sort" +                                             "\nI - Insertion Sort" +                                             "\nS - Selection Sort");

order = JOptionPane.showInputDialog("How do you want to display the sorted numbers?" +                                           "\nA - Ascending Order" +                                            "\nD - Descending Order");

if(choice.equalsIgnoreCase("B")){

while (doMore) { doMore = false; for (int i=0;i array[i+1]) { int swap = array[i]; array[i] = array[i+1]; array[i+1] = swap; doMore = true; }

}            }

if(order.equalsIgnoreCase("A")) JOptionPane.showMessageDialog(null,Arrays.toString(array)); else if(order.equalsIgnoreCase("D")){ for(int i=0,j=array.length-1;i=0; i--){ for(int j = 4; j > 0;j--){ if (array[j] < array[j-1]) { int swap = array[j-1]; array[j-1] = array[j]; array[j] = swap; }               }             }            if(order.equalsIgnoreCase("A")) JOptionPane.showMessageDialog(null,Arrays.toString(array)); else if(order.equalsIgnoreCase("D")){ for(int i=0,j=array.length-1;i array[j]) { int swap = array[i]; array[i] = array[j]; array[j] = swap; }               }            }

if(order.equalsIgnoreCase("A")) JOptionPane.showMessageDialog(null,Arrays.toString(array)); else if(order.equalsIgnoreCase("D")){ for(int i=0,j=array.length-1;i<array.length;i++,j--){ array2[i] = array[j]; }               JOptionPane.showMessageDialog(null,Arrays.toString(array2)); }       }        }    }