Selection sort ,the last value not reversing

package project_1;

public class SelectionSort {

public static void main(String[] args) {
	// TODO Auto-generated method stub
	int[] arr= {55,43,37,23,12};
	
	SelectionSort(arr);
	display(arr);
	
}

public static void SelectionSort(int[] arr) {
	
	for(int counter=0;counter<arr.length-1;counter++) {
		
		int min =counter;
		
		for (int j=min+1; j<arr.length-1; j++){
	      
			if(arr[j]<arr[min])
			{
				min=j;
			}
		
		if (min !=counter)
		{
			int temp=arr[min];
			arr[min]= arr[counter];
			arr[counter]= temp;
				}
	}
			}
	

}

public static void display(int[] a)
{
	for(int i=0;i<a.length;i++)
		System.out.print(a[i] +" ");   	

}

		}

Hi @Manan-Kanswal-2097696493645790,
In both the for loops you are using condition j<arr.length-1 and i <arr.length-1 . that should be j<arr.length and i<arr.length for correct implementation . You are missing a last value . And if the error still remains please send the code after saving on ide.codingblocks.com. Hope this helps.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.