Define a function named LargestNumber that takes three integers as parameters and returns the largest integer. Define a second function named SmallestNumber that takes three integers as parameters and returns the smallest integer. Then, write a main program that reads three integers as inputs, calls functions LargestNumber() and SmallestNumber() with the inputs as arguments, and outputs the largest and the smallest of the three input values. CORAL

Respuesta :

Answer:

Explanation:

The following code is written in Java and creates both of the requested methods. The methods compare the three inputs and goes saving the largest and smallest values in a separate variable which is returned at the end of the method. The main method asks the user for three inputs and calls both the LargestNumber and SmallestNumber methods. The output can be seen in the attached image below.

import java.util.Scanner;

class Brainly {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       System.out.println("Enter number 1: ");

       int num1 = in.nextInt();

       System.out.println("Enter number 2: ");

       int num2 = in.nextInt();

       System.out.println("Enter number 3: ");

       int num3 = in.nextInt();

       System.out.println("Largest Value: " + LargestNumber(num1, num2, num3));

       System.out.println("Smallest Value: " + SmallestNumber(num1, num2, num3));

   }

   public static int LargestNumber(int num1, int num2, int num3) {

       int max = num1;

       if (num2 > num1) {

           max = num2;

       }

       if (num3 > max) {

           max = num3;

       }

       return max;

   }

   public static int SmallestNumber(int num1, int num2, int num3) {

       int smallest = num1;

       if (num2 < num1) {

           smallest = num2;

       }

       if (num3 < smallest) {

           smallest = num3;

       }

       return smallest;

   }

}

Ver imagen sandlee09

The algorithm consists in a main routine that calls two functions based on if-cycles to determine the minimum and the maximum of a set of three integers, whose construction can revised below.

In this question we must define a main algorithm in which three integers are introduced and functions LargestNumber() and SmallestNumber() are called and outputs are printed:

INPUTS

Integers num1, num2, num3;

OUTPUTS

Integers min, max;

MAIN ALGORITHM

Print "Write the first integer";

Write num1;

Print "Write the second integer";

Write num2;

Print "Write the third integer";

Write num3;

min = SmallestNumber(num1, num2, num3);

max = LargestNumber(num1, num2, num3);

Print "The smallest of the three input values is " min;

Print "The largest of the three input values is " max;

FUNCTION SmallestNumber()

if (((num1 <= num2) and (num2 <= num3)) or ((num1 <= num3) and (num3 <= num2))) then:

     min = num1;

else if (((num2 <= num1) and (num1 <= num3)) or ((num2 <= num3) and (num3 <= num1))) then:

    min = num2;

else:

    min = num3;

return min;

FUNCTION LargestNumber()

if (((num1 >= num2) and (num2 >= num3)) or ((num1 >= num3) and (num3 >= num2))) then:

     max = num1;

else if (((num2 >= num1) and (num1 >= num3)) or ((num2 >= num3) and (num3 >= num1))) then:

    max = num2;

else:

    max = num3;

return max;

To learn more on algorithms, we kindly invite to check this verified question: https://brainly.com/question/22952967