Question_3

PHOTO EMBED

Tue May 30 2023 19:37:12 GMT+0000 (Coordinated Universal Time)

Saved by @Mohamedshariif #java

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]
content_copyCOPY