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

前端 未结 6 1035
旧巷少年郎
旧巷少年郎 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:11

    int mid = num1 + num2 + num3 - min - max;
    

    Sorry for briefness - posted from my phone.

    It must be self-evident that the middle number is the sum of the three numbers minus the max minus the min. Would also work if max == mid or max == min or even both.

提交回复
热议问题