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

前端 未结 6 1032
旧巷少年郎
旧巷少年郎 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 01:16

    Assuming this is some kind of puzzle/homework are you allowed to use the ternary operator?

    int[] ints = {3, 1, 2};
    int min = ints[0] <= ints[1] && ints[0] <= ints[2]
              ? ints[0]
              : ints[1] <= ints[0] && ints[1] <= ints[2]
                ? ints[1]
                : ints[2];
    

提交回复
热议问题