+ 1

Can you check the Java code and tell me why this Array is not sorting by using Array.sort(); [Solved]

https://code.sololearn.com/cA87a19a10a1

6th Feb 2021, 2:28 AM
Ray
Ray - avatar
5 Answers
+ 5
Rabeeh You are sorting array on index based so your array elements will sort on the basis of that range so here you have sort array from index 1 to 3 so here only 23 and 53 will sort which is already sorted. Here index 1 element is included and index 3 element is excluded Try to change index 3 to 4 then see effect. https://code.sololearn.com/cJM6SxWFy45i/?ref=app
6th Feb 2021, 4:27 AM
AÍąJ
AÍąJ - avatar
+ 3
Your code works fine and what you want to do with your code . .? Do you want to sort sub array of elements. .? If yes, your procedure is right ✅. This is the method of sorting sub array of elements which is in java.util.Arrays; public static void sort(int[] arr, int from_Index, int to_Index) first argument took the array , second and third arguments tooks integer numbers those represents starting index(inclusive) and ending index(exclusive) of sub array . Note : it is useful for unsorted sub array . but in your array elements the sub array from index 1 to 3 (exclusive) means only two elements 23 and 53 already sorted . so no need to sorted it again . Hope you get ... H A P P Y C O D I N G 😊
6th Feb 2021, 2:54 AM
NavyaSri
NavyaSri - avatar
+ 3
đŸŒŸÎ±nurαg kumαr🌟 That's not valid answer. You need to check first why there is 1, 3 in sort method.
6th Feb 2021, 4:30 AM
AÍąJ
AÍąJ - avatar
+ 2
Thank you Guys. I really understood what you say 🙏 I Am AJ ! Navya Sri 💕
6th Feb 2021, 4:54 AM
Ray
Ray - avatar