answersLogoWhite

0


Best Answer

Make use of Java's robust library:

// filled with various ints

int[] a;

// temporary variable for swapping values

int temp;

// sort with fast, built-in algorithm

java.util.Arrays.sort(a);

// reverse the array

for( int i = 0; i < a.length/2; ++i ) {

temp = a[i];

a[i] = a[a.length - i - 1];

a[a.length - i - 1] = temp;

}

Obviously, if you're concerned with execution speed you could write your own sort method which would sort into descending order instead of ascending order (perhaps by modifying Java's sort algorithm).

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Sort the array of integers in Descending order?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Sort array in ascending descending order in python?

Using sorted(array,reverse=True)


C program to solve the given array element in descending order?

#include#includeint main(){long int sort[10],i,j,t;printf("\n\ n Enter 10 Elements In Array To Sort In Descending Order:\n"); for(i=0;i


How do you sort variable in ascending or descending order both in php?

Assuming that the values are stored in an array, you can use the php function sort($array) to sort ascending, and rsort to sort descending. The following link gives a table that lists all of the built in PHP sort functions: http://php.net/manual/en/array.sorting.php


How use array sort program in c sharp?

Assume an array of integers (size &gt; 0) to be sorted in descending order. And the values have been populated already: const int size = 50; //by changing the value here int[] array = new int[](); // omit the initialization of array Array.Sort(array); // array will be changed with ascending order Array.Reverse(array); // change from ascending to descending NOTE: Array.Sort() and Array.Reverse() are 2 of the functions in the class library. We do not care the algorithm being used within the functions, just the result. Also noted that the these 2 functions do change the content of the source array. It may not be what you want


Which action do you perform on a data source to reorganize the order of the record for a merge?

You can sort the data in ascending or descending order.You can sort the data in ascending or descending order.You can sort the data in ascending or descending order.You can sort the data in ascending or descending order.You can sort the data in ascending or descending order.You can sort the data in ascending or descending order.You can sort the data in ascending or descending order.You can sort the data in ascending or descending order.You can sort the data in ascending or descending order.You can sort the data in ascending or descending order.You can sort the data in ascending or descending order.


Can you modify the bubble sort algorithm to search to sort an array of characters instead of array of integers?

The bubble sort algorithm can be applied to an array of characters. Every character can be translated to an integer equivalent via the ascii table


What is a descending sort order?

When you sort numbers from largest to smallest, or sort text from Z to A (in reverse alphabetical order).


Write a function in java that accepts an array of integers and returns the second largest integer in the array Return -1 if there is no second largest?

Method 1: Sort the array in descending order, compare 1st and 2nd if not same , return 2nd if same return -1 Method 2: Find the largest number in the array, initialize another array with dimension 1 less than of original. Copy the array elements from the original array minus the largest element. not select largest from the second array and compare with the previous one if not same return the second largest if same return -1


What two ways can you sort information?

In ascending order and in descending order.


How do you display a student record in descending order?

Select the area you want to sort and select sort descending (High to Low; e.g. Z - A).


What does descending mean in Microsoft access?

Descending order is when you sort numbers from largest to smallest, or sort text from Z to A (in reverse alphabetical order), or dates from most recent to oldest. Usually we sort in ascending order, but sometimes we want to format in descending order.


What button do you use to put data in a specific order?

The sort buttons. You can use them to sort in ascending order or descending order. One has A above Z with a down arrow enabling you to sort in ascending order. The other has Z above A with a down arrow enabling you to sort in descending order. Once your data is selected, you can click the appropriate button to do the sort you want.