3 numbers in ascending order WITHOUT the use of conditional statements in Java. As in I can't use if statements at all

前端 未结 6 1041
旧巷少年郎
旧巷少年郎 2021-01-25 00:24

My code looks like this so far:

public class ThreeSort {
    public static void main(String[] args) {

        int num1 = Integer.parseInt(args[0]);
        int          


        
6条回答
  •  佛祖请我去吃肉
    2021-01-25 00:56

    Put them in a List and sort it...

    List ints = new LinkedList<>();
    ints.add(Integer.parseInt(args[0]));
    ints.add(Integer.parseInt(args[1]));
    ints.add(Integer.parseInt(args[2]));
    
    Collections.sort(ints); // smallest -> greatest
    System.out.println(ints);
    
    Collections.reverse(ints); // greatest -> smallest
    System.out.println(ints);
    

提交回复
热议问题