sorted, shuffled, reversed
Hello, I’m trying to write a program that takes in numbers until a sentinel value is entered then displays a sorted, shuffled and reversed?
So far this is what I have come up with.
I know I need to implement the comparator but I’m not sure how too.
Could you provide some feedback?
Thanks
Public class SortShuffle {
public static void main(String[] args) {
Collection<Integer> list = new ArrayList<Integer>();
Scanner scan = new Scanner (System.in);
System.out.println (" Input Number : ( 0 to exit ) ");
int data = scan.nextInt();
int sum = 0;
while (data != 0) {
sum +=data;
System.out.println (" Input Number : ( 0 to exit ) ");
data = scan.nextInt();
list.add(data);
}
System.out.println (" The sorted numbers are ");
Collections.sort(list);
System.out.println (" The shuffled numbers are ");
Collections.shuffle((java.util.List<?>) list);
System.out.println (" The reversed numbers are ");
Collections.reverseOrder();
}
}