public static void main(String[] args) { //First Way int[] myArray={1,2,33,56,34,85,32}; Arrays.sort(myArray); System.out.println(Arrays.toString(myArray)); } } //Second Way public class QuestionsOfLab_12 { //Lab 11 _ Question _3: public static void main(String[] args) { int[] array = {2,9,5,10,-1,0}; bubbleSort(array); System.out.println("Array after sorting is : " + Arrays.toString(array)); } public static void bubbleSort(int[] array) { for(int i=0; i<array.length; i++) { for(int j=0; j<array.length-1-i; j++) { if(array[j] > array[j+1]) { int temp = array[j]; array[j] = array[j+1]; array[j+1] = temp; } } } } } Output: Array after sorting is : [-1, 0, 2, 5, 9, 10]
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter