0

whats wrong in this code for java (bubblesort) errors are coming only one error

class bubblesort { static void bubblesort(int arr[]) { int n = arr.length; int temp = 0; int j; int i; for(i=0;i<n;i++) { for(j=1;j<(n-1);j++) { if(arr[j-1]<arr[j]) { temp = arr[j-1]; arr[j-1] = arr[j]; arr[j] = temp; } } } } public static void main(String[] args) { int arr[] = {3,60,35,2,45,320,5}; System.out.println("array before bubble sort"); for(int i=0;i<arr.length;i++) { System.out.println(arr[i] + " "); } System.out.println(); bubblesort(arr); System.out.print(arr[]+ " "); }

27th Aug 2020, 8:29 AM
Sunita Zirange
Sunita Zirange - avatar
5 Respuestas
+ 3
class BubbleSort { static void bubbleSort(int[] arr) { int n = arr.length; int temp = 0; for(int i=0; i < n; i++){ for(int j=1; j < (n-i); j++){ if(arr[j-1] > arr[j]){ temp = arr[j-1]; arr[j-1] = arr[j]; arr[j] = temp; } } } } public static void main(String[] args) { int arr[] ={3,60,35,2,45,320,5}; System.out.println("Array Before Bubble Sort"); for(int i=0; i < arr.length; i++){ System.out.print(arr[i] + " "); } System.out.println(); bubbleSort(arr); System.out.println("Array After Bubble Sort"); for(int i=0; i < arr.length; i++){ System.out.print(arr[i] + " "); }} }
27th Aug 2020, 8:57 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 2
Yes your main function u wrote System.out.print(arr[]+ " ") ; this is wrong and check parenthesis .check this one
27th Aug 2020, 8:55 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
thanks you very much guys ! :) thanks for giving ur precious time to me! i will recorrect it! talk to you all later!
27th Aug 2020, 9:30 AM
Sunita Zirange
Sunita Zirange - avatar
+ 1
thanks to everyone who have answered my question :)
27th Aug 2020, 9:31 AM
Sunita Zirange
Sunita Zirange - avatar