# how I make the numbers in descending order ?

abdo
how I make the numbers in descending order ?
2 Answer(s)      5 years and a month ago
Posted in : Java Beginners

public class Quiz1 { public static void main (String [] abdo){ Scanner sc = new Scanner(System.in); int number [] = new int [20]; int num =2; for(int i =0; i< number.length; i++){ System.out.print("Insert value number"+(i+1)+":"); number[i]= sc.nextInt(); }

System.out.print("the numbers are: ");
for(int u=0; u< number.length; u++){
System.out.print(number[u]+" ");
}
}

thanks how I make the numbers in descending order ?

May 28, 2012 at 1:43 PM

The given code allow the user to enter 20 numbers and display them in descending order.

import java.util.*;

public class Quiz1 {
public static void main (String [] str){
Scanner sc = new Scanner(System.in);
int number [] = new int [20];
int num =2;
for(int i =0; i< number.length; i++){
System.out.print("Insert value number"+(i+1)+":");
number[i]= sc.nextInt();
}
System.out.println("Numbers in descending order: ");
for(int i=number.length-1;i>=0;i--){
System.out.println(number[i]);
}
}
}

May 29, 2012 at 12:42 AM

Hi,

Sorting can be done in many ways. I can give two simple ways.