tag:blogger.com,1999:blog-8712770457197348465.post3295399759734251357..comments2024-03-28T02:47:19.159-07:00Comments on Javarevisited: How to sort an Array in Java? Ascending and Descending Order Examplejavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-8712770457197348465.post-3064921806375025342017-06-04T05:11:33.550-07:002017-06-04T05:11:33.550-07:00Hy guys here is the program of sort ascending and ...Hy guys here is the program of sort ascending and descending without the sort method:<br /><br /><br /><br /><br /><br />import java.util.Scanner;<br /><br />public class Experiment<br />{<br /> public static void main(String args[])<br /> {<br /> Scanner scan = new Scanner(System.in);<br /> int tenNums[]=new int[10], orderedNums[]=new int[10];<br /> int greater;<br />Maria Khanhttps://www.blogger.com/profile/05488694087269318857noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-69331019906269727032017-02-10T22:07:04.251-08:002017-02-10T22:07:04.251-08:00CMD could not found or load main class
where i was...CMD could not found or load main class<br />where i was mistake please check<br />import java.util.Scanner;<br />class Ascending_Order <br />{<br />public static void main(String args[]) <br /> {<br /> int n, temp;<br /> Scanner s = new Scanner(System.in);<br /> System.out.print("Enter no. of elements you want in array:6");<br /> n = s.nextInt();<br />Anonymoushttps://www.blogger.com/profile/10418930339497041879noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-71695434688160389782016-06-07T08:09:21.458-07:002016-06-07T08:09:21.458-07:00Unfortunately, there is no way to sort a primitive...Unfortunately, there is no way to sort a primitive array in reverse or descending order by using Array.sort() method. Only reasonable way is to sort the array in ascending order and then <a href="http://java67.blogspot.com/2016/01/java-program-to-reverse-array-in-place.html" rel="nofollow">reverse the array in place</a> as shown in that article. Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-16536989524455025202016-05-21T19:45:19.842-07:002016-05-21T19:45:19.842-07:00Hello Shailesh, what is the type of numbers array?...Hello Shailesh, what is the type of numbers array? if it's a primitive array e.g. an int array then it will not work because Array.sort() method accepts array of objects e.g. Integer, String or Short. This limitation because Comparator can only compare objects. <br /><br />int[] numbers = {1, 2, 3};<br /> Arrays.sort(numbers, 0, numbers.length-1, Collections.reverseOrder()); // not ok<br />javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-12428303148196318672016-05-21T11:49:50.798-07:002016-05-21T11:49:50.798-07:00hi please help me if i am using
Arrays.sort(numbe...hi please help me if i am using <br />Arrays.sort(numbers, 0, numbers.length-1, Collections.reverseOrder());<br /><br />it is saying this argument is not applicable<br /><br /><br /><br /> public static Comparator reverseOrder(Comparator cmp) {<br /> if (cmp == null)<br /> return reverseOrder();<br /><br /> if (cmp instanceof ReverseComparator2)<br /> return (Anonymoushttps://www.blogger.com/profile/13450276947419664076noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-40429369803692980132015-01-07T07:49:33.649-08:002015-01-07T07:49:33.649-08:00There are couple of other ways to sort array in Ja...There are couple of <a href="http://java67.blogspot.com/2014/08/4-examples-to-sort-array-in-java.html" rel="nofollow">other ways to sort array in Java</a> e.g. by using bubble sort, quick sort or insertion sort. Though Java only support quicksort via java.util.Arrays class, you can still write this sorting algorithm code by your own.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-52721623818649139452014-08-15T02:22:31.710-07:002014-08-15T02:22:31.710-07:00One of the most important thing to know about Arra...One of the most important thing to know about Arrays.sort() method is that it uses two pivot quicksort algorithm to sort primitives while a stable mergesort algorithm to sort objects. In addition, there is one more overloaded version of sort(array, Comparator) which takes comparator to sort array in custom order, and can be uesd to sort in reverse order. By the way, sorry to say but no easy way Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-34782330208347473402013-01-22T01:30:09.182-08:002013-01-22T01:30:09.182-08:00int minval = input[0];
int temp=0;
for(int...int minval = input[0];<br />int temp=0;<br /> for(int i = 0; i< input.length; i++)<br /> { <br /> for(int j = 0; j< input.length-1; j++)<br /> {<br /> if(input[j+1]<input[j])<br /> {<br /> temp=input[j+1];<br /> input[j+1]=input[j];<br /> input[j]=temp; <br /> }<br /> }<br /> }Anonymoushttps://www.blogger.com/profile/05158778779628438015noreply@blogger.com