Advertisement
ZazoTazo

ArrayList Descending Order

Jun 30th, 2019
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. package com.zazospackage;
  2.  
  3. import java.util.*;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner input = new Scanner(System.in);
  9.         ArrayList<Integer> numbers = new ArrayList<>();
  10.         int number;
  11.         System.out.println("Welcome to the sorting program, enter the numbers you wish to be sorted.");
  12.         System.out.println("Type -1 to stop entering numbers.");
  13.         do{
  14.             System.out.print("Number: ");
  15.             number = input.nextInt();
  16.             numbers.add(number);
  17.         }while(number != -1);
  18.         Collections.sort(numbers, Collections.reverseOrder());
  19.         for(int i=0; i < numbers.size(); i++){
  20.             if(numbers.get(i) == -1){
  21.                 numbers.remove(i);
  22.             }
  23.             else {
  24.                 System.out.println(numbers.get(i));
  25.             }
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement