-3

I need to make the two methods below return the maximum and minimum of three numbers, but I keep getting an error saying that it cannot find the symbol MaxOf3 in 12 line and MinOf3 in line 15 in the main method above the other two. How do I fix this???

I looked it up on the internet, but I could not find the right solution.

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;
    }   
}
Butiri Dan
  • 1,759
  • 5
  • 12
  • 18
Janjey
  • 3
  • 2

1 Answers1

1

You get the error because you haven't implement MaxOf3/MinOf3, but you can remove them and use findMax/finaMin

  1. Adapt the findMax/finaMin to get 3 int parameters and to return the max/min of them
  2. Call findMax/finaMin instead of 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;
}

Output

8
9
1
The maximum is 9
Maximum: 9
The minimum is 1
Minimum: 1
Butiri Dan
  • 1,759
  • 5
  • 12
  • 18