java if_else 实现三个数最大值和分段函数(java if_ Else implements three maximum values and piecewise functions)

import java.util.Scanner;

public class Hello {
    public static void main(String[] args) {
    
        Scanner in = new Scanner(System.in);
        // else 与 最近的 if 匹配
        int x = in.nextInt();
        int y = in.nextInt();
        int z = in.nextInt();
        int max;
        if (x > y) {
            if (x > z)
                max = x;
            else
                max = z;
        }else {
            if(y > z)
                max = y;
            else
                max = z;
        }
        System.out.println(max);
    }
}
import java.util.Scanner;

public class Hello {
    public static void main(String[] args) {
    // 级联
        Scanner in = new Scanner(System.in);
        // else 与 最近的 if 匹配
        int x = in.nextInt();
        int f;
        if (x < 0)
            f = -1;
        else if (x == 0)
            f = 0;
        else
            f = 2 * x;
        System.out.println(f);
    }
}
————————
import java.util.Scanner;

public class Hello {
    public static void main(String[] args) {
    
        Scanner in = new Scanner(System.in);
        // else 与 最近的 if 匹配
        int x = in.nextInt();
        int y = in.nextInt();
        int z = in.nextInt();
        int max;
        if (x > y) {
            if (x > z)
                max = x;
            else
                max = z;
        }else {
            if(y > z)
                max = y;
            else
                max = z;
        }
        System.out.println(max);
    }
}
import java.util.Scanner;

public class Hello {
    public static void main(String[] args) {
    // 级联
        Scanner in = new Scanner(System.in);
        // else 与 最近的 if 匹配
        int x = in.nextInt();
        int f;
        if (x < 0)
            f = -1;
        else if (x == 0)
            f = 0;
        else
            f = 2 * x;
        System.out.println(f);
    }
}