java 从键盘输入任意三个数,求最大值。

//4、从键盘输入任意三个数,求最大值。
package ErShinihao;

import java.util.Scanner;

public class h4 {
    public static void main(String[] args) {
        //4、从键盘输入任意三个数,求最大值。
        Scanner in= new Scanner(System.in);
        System.out.println("请你输入第一个数");
        int a = in.nextInt();
        System.out.println("请你输入第二个数");
        int b = in.nextInt();
        System.out.println("请你输入第三个数");
        int c = in.nextInt();

        int max;//最大值
        int min;//最小值

        if (a>b){
            max = a;
            min = b;
        }else {
            max = b;
            min = a;
        }if (max < c){
            max = c;
        }if (c < min){
            min = c;
        }
        System.out.println("最大值为"+max + "最小值"+min );
    }
}

猜你喜欢

转载自blog.csdn.net/Relievedz/article/details/123089984
今日推荐