Java Program: How to Sort Numbers in an Array in a Descending Order

Java Program: How to Sort Numbers in an Array in a Descending Order
NEW 4″ Multi-Touch Android 4.0 Smart Phone Dual SIM WIFI Unlocked AT&T T-Mobile
Current Bid: $63.96

Java Program: Sort Numbers in Descending Order with a Sample Java Source Code

The Java source code of sorting number in descending order is just slightly different with the java source code of sorting number in ascending order. The algorithm for sorting in descending order is this: If the entered number is greater than the next, the program should do nothing, as we want the greater number to come first. Otherwise, if the number is smaller than the next entered number, the program should swap the 2 numbers in order to meet the goal of sorting in descending order. Then the program will continue to behave like this till all numbers in the array are checked.

Other Sorting Java Programs

Java Source Code in Sorting: How to Sort Numbers in Ascending Order
Java Code Sample: Sort Numbers in Bubble Sort
Java Source Code: Sort Numbers in Selection Sort

Java Source Code for Descending Order

package sort_numbers_in_descending_order;
import java.util.Scanner;
public class Main {
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print(“How Many Numbers You Want to Sort? “);
int size = input.nextInt();
int[] newArr = new int [size];
System.out.print(“Enter ” + size + ” Numbers to Sort: “);
for(int input_array = 0; input_arraySample Output:

Related Java Tutorials:

Complete List of Java Tutorial and Source Codes for Absolute Beginners
5 Important Tips to Learn Java Programming and Other Programming Languages
Basic Knowledge Required in Programming
How to Program in Java Using Netbeans: Complete Simple Easy Steps
Java Simple Codes for Beginners
Java Tutorial for Beginners: A Beginners Guide on Learning Java Programming

Java Books for Beginners

Programming with Java : A Multimedia Approach by Radhika S. Grover (2011,…
Current Bid: $.99
Introduction to Java Programming, Comprehensive Version 9e by Y. Daniel Liang
Current Bid: $50.80
Beginning Programming With Java for Dummies by Barry Burd (2012, Paperback)
Current Bid: $20.76

Other Java Source Code Samples:

Java Program: Palindrome Test Java Source Code
Java Program: Using Multi If and Else Statement in Java Programming
Java Program: Count the Number of String Characters in Java
Java Program: How to Parse a String into Integer in Java Programming
Java Source code: Reverse String in Java Using Recursion
Java Program: Reverse String in Java Using For Loop
Java Program: How to Use If Statement in Java Programming
Java Program: How to Use Switch Statement in Java
Class in Java: Learn More about Java Classes with Sample Java Codes
Java Source Code Recursion: Recursive Koch Snow Flakes
Java Source code on Printing the Greatest Common Divisor (GCD) using Recursion
Java Source code: How to Add numbers inside an Array Using Recursion
Java Source Code in a Recursive Linear Search
Java Source Code: A Recursive Asterisk Diamond Shape Program
Java source code in Recursive function for X to the power Y
Java Source Code: Binary Search in Recursion
Java Source code sample: How to Add Numbers inside an Array using For Loop
Java source code Sample: Print Different Asterisk Shapes in Recursion