It seems like you've made a few errors in your code. Here's a corrected version:
public class BubbleSort1 {
public static void main(String[] args) {
int arrays[] = {5, 3, 2, 1, 51, 23};
System.out.print("Arrays Before Sorted: ");
for (int i = 0; i < arrays.length; i++) {
System.out.print(arrays[i] + " ");
}
System.out.println(); // Move this line outside the loop to print on a new line
bubbleSort(arrays);
System.out.print("Arrays Sorted: ");
for (int i = 0; i < arrays.length; i++) {
System.out.print(arrays[i] + " ");
}
}
private static void bubbleSort(int[] arrays) {
int n = arrays.length;
int temp = 0;
for (int i = 0; i < n; i++) { // Change the loop condition to n
for (int j = 1; j < (n - i); j++) { // Change the loop condition to (n - i)
if (arrays[j - 1] > arrays[j]) {
temp = arrays[j - 1];
arrays[j - 1] = arrays[j];
arrays[j] = temp;
}
}
}
}
}
if you ever need additional support or assistance with your programming homework, you can check out
https://www.programminghomeworkhelp....va-assignment/ for expert guidance and solutions.