public class BubbleSort {
public static void bubbleSort(int[] arr) {
int n = arr.length;
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
// Swap arr[j] and arr[j+1]
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
public static void main(String[] args) {
int[] arr = {64, 34, 25, 12, 22, 11, 90};
System.out.println("Array before sorting:");
for (int num : arr) {
System.out.print(num + " ");
}
bubbleSort(arr);
System.out.println("\nArray after sorting:");
for (int num : arr) {
System.out.print(num + " ");
}
}
}
Java Collection Framework Most Important Questions Q:-1 What is Collection Framework ? A:- Collection framework is a unified architecture or predefined java classes and interfaces that is used for implementing a group of objects in java. Q:-2 What is Collection ? A:- A collection represents a group of objects. And it is root interface of java collection hierarchy. Q:-3 What is Collections ? A:- Collections is a utility class in java which is present is java.util package for manipulating data. It provides static method for searching, sorting and more. Q:-4 What is difference between Array and Collection ? A:- Array ...
Comments
Post a Comment