如何修复'无法找到符号MaxOf3和MinOf3'错误

时间:2019-09-10 21:06:17

标签: java

我需要使下面的两个方法返回三个数字的最大值和最小值,但是我不断收到错误消息,指出在其他两个方法的上面的主方法中,它找不到12行中的MaxOf3符号和15行中的MinOf3符号。我该如何解决???

我在互联网上进行了查找,但是找不到正确的解决方案。

import java.util.Scanner;

public class MaxAndMin {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n1 = in.nextInt();
        int n2 = in.nextInt();
        int n3 = in.nextInt();

        int max = MaxOf3(n1,n2,n3);
        System.out.println("Maximum: " + max);

        System.out.println("Minimum: " + MinOf3(n1,n2,n3));
    }

    public static int findMax(int max) {
        int maximum = Math.max(8, 9);
        int maximum2 = Math.max(maximum, 1);
            System.out.println("The maximum of 8, 9, and 1 is " + maximum2);
            return maximum2;
    }

    public static int findMin(int min) {
        int minimum = Math.min(8, 9);
        int minimum2 = Math.min(minimum, 1);
            System.out.println("The minimum of 8, 9 and 1 is " + minimum2);
                return minimum2;
    }   
}

1 个答案:

答案 0 :(得分:1)

由于未实现MaxOf3 / MinOf3而收到错误,但是您可以删除它们并使用findMax / finaMin

  1. 调整findMax / finaMin以获得3个int参数并返回它们的最大值/最小值
  2. 致电findMax / finaMin而不是MaxOf3 / MinOf3
public static void main(String[] args) {
    Scanner in = new Scanner(System.in);

    int n1 = in.nextInt();
    int n2 = in.nextInt();
    int n3 = in.nextInt();

    int max = findMax(n1, n2, n3);
    System.out.println("Maximum: " + max);

    System.out.println("Minimum: " + findMin(n1, n2, n3));
}

public static int findMax(int n1, int n2, int n3) {
    int maximum = Math.max(n1, n2);
    int maximum2 = Math.max(maximum, n3);
    System.out.println("The maximum is " + maximum2);
    return maximum2;
}

public static int findMin(int n1, int n2, int n3) {
    int minimum = Math.min(n1, n2);
    int minimum2 = Math.min(minimum, n3);
    System.out.println("The minimum is " + minimum2);
    return minimum2;
}

输出

8
9
1
The maximum is 9
Maximum: 9
The minimum is 1
Minimum: 1