Exercise - Complete a challenge activity to discover and implement a method call

Completed

Code challenges will reinforce what you've learned and help you gain some confidence before continuing on.

Math class methods challenge

In this challenge, you'll use either Intellisense or learn.microsoft.com to find and call a method that returns the larger of two numbers.

Code challenge: Implement a method of the Math class that returns the larger of two numbers

Here are your challenge requirements:

  1. Ensure that you have an empty Program.cs file open in Visual Studio Code.

  2. Enter the following code as the starting point for your challenge.

    int firstValue = 500;
    int secondValue = 600;
    int largerValue;
    
    Console.WriteLine(largerValue);
    
    

    Note

    Your final solution for this challenge must use this code, and must use the Console.WriteLine(largerValue); statement to generate the output.

  3. Find a method of the System.Math class that returns the larger of two numbers.

    You can use either Visual Studio Code "Intellisense" or learn.microsoft.com to find the method and determine how to call it properly.

  4. Use the method that you found to assign a value to the variable named largerValue.

    You should be able to pass the two integer values, firstValue and secondValue, to the method that you found. The method should return a value of type int that represents the larger of the two arguments that you passed it.

    You can assign the return value to largerValue on a new code line or on the existing code line that's used to declare largerValue.

  5. Verify that your application writes the following output:

600

Whether you get stuck and need to peek at the solution or you finish successfully, continue on to view a solution to this challenge.