首页 > 试题广场 >

最大最小值

[编程题]最大最小值
  • 热度指数:31773 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
\hspace{15pt}给定三个整数 a,b,c1 \leqq a,b,c \leqq 10^6),请输出它们中的最大值和最小值。

输入描述:
\hspace{15pt}在一行中输入三个整数 a,b,c1 \leqq a,b,c \leqq 10^6),用空格隔开。


输出描述:
\hspace{15pt}输出两行:
\hspace{23pt}第一行输出 `The maximum number is : X`,其中 X 为最大值;
\hspace{23pt}第二行输出 `The minimum number is : Y`,其中 Y 为最小值。
示例1

输入

1 2 3

输出

The maximum number is : 3
The minimum number is : 1

说明

输入为 1,2,3,最大值为 3,最小值为 1

备注:
\hspace{15pt}注意输出内容的冒号前后均有空格。
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        int max;
        int min;
        if(a>b){
        max=(a>c)?a:c;
        min=(b<c)?b:c;
        }else if(b>a){
            max = (b>c)?b:c;
            min = (c<a)?c:a;
        }else{
            max = (c>b)?c:b;
            min = (b<a)?b:a;
        }
        System.out.println("The maximum number is : "+max);
        System.out.println("The minimum number is : "+min);
    }
}
发表于 2026-01-28 09:49:22 回复(0)
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
                int a = in.nextInt();
                int b = in.nextInt();
                int c = in.nextInt();
                int temp = a>b ?a:b;
                int max = temp>c ? temp:c;
                int ou = a<b ?a:b;
                int min = ou<c ? ou:c;
                System.out.println("The maximum number is : "+max);
                System.out.println("The minimum number is : "+min);
     }
}
发表于 2026-01-20 14:51:31 回复(0)
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        //使用Scanner录入三个整数a,b,c
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        //使用if进行判断,输出最大最小值
        if (a > b && a > c) {
            System.out.println("The maximum number is : " + a);
            if (b > c) {
                System.out.println("The minimum number is : " + c);
            } else {
                System.out.println("The minimum number is : " + b);
            }
        } else {
            if (b > c) {
                System.out.println("The maximum number is : " + b);
                if (a < c) {
                    System.out.println("The minimum number is : " + a);
                } else {
                    System.out.println("The minimum number is : " + c);
                }
            } else {
                System.out.println("The maximum number is : " + c);
                if (a < b) {
                    System.out.println("The minimum number is : " + a);
                } else {
                    System.out.println("The minimum number is : " + b);
                }
            }
        }
    }
}
发表于 2025-10-31 16:40:49 回复(0)
import java.util.*;
public class Main{
    public static void main(String[] args){
           Scanner in = new Scanner (System.in);
           while (in.hasNextInt()){
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            int d = 0;
            if (a<b){
                if (c<a){a=c;}
                else if (c>b){b=c;}
            }
            else { d=a;a=b;b=d;
                if (c<a){a=c;}
                else if (c>b){b=c;}
            }

            System.out.println("The maximum number is : " + b);
            System.out.println("The minimum number is : " + a);
           }
    }
}
发表于 2025-10-16 09:30:04 回复(0)
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        if (a < b) {
            if (b < c) {
                System.out.println("The maximum number is : " + c);
                System.out.println("The minimum number is : " + a);
            } else {
                if (c < a) {
                    System.out.println("The maximum number is : " + b);
                    System.out.println("The minimum number is : " + c);
                } else {
                    System.out.println("The maximum number is : " + b);
                    System.out.println("The minimum number is : " + a);
                }
            }
        }  else if(a > b){
                if (a < c) {
                    System.out.println("The maximum number is : " + c);
                    System.out.println("The minimum number is : " + b);
                } else {
                    if (b < c) {
                        System.out.println("The maximum number is : " + a);
                        System.out.println("The minimum number is : " + b);
                    } else {
                        System.out.println("The maximum number is : " + a);
                        System.out.println("The minimum number is : " + c);
                    }
                }
           
        } else {
            System.out.println("The maximum number is : " + a);
            System.out.println("The minimum number is : " + b);
        }

    }
} 无脑算法
发表于 2025-09-06 21:54:54 回复(0)
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String[] s = in.nextLine().split(" ");
            int a = Integer.parseInt(s[0]);
            int b = Integer.parseInt(s[1]);
            int c = Integer.parseInt(s[2]);
            int max = a > b ? a : b > c ? b : c;
            int min = a < b ? a : b < c ? b : c;
            System.out.println("The maximum number is : " + max);
            System.out.println("The minimum number is : " + min);
        }
    }
}

发表于 2025-08-29 16:06:41 回复(0)
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            int max = Math.max(Math.max(a,b),c);
            int min = Math.min(Math.min(a,b),c);
            System.out.println("The maximum number is : "+max);
            System.out.println("The minimum number is : "+min);
    }
}

发表于 2025-08-13 15:04:21 回复(0)