Ask Question
11 April, 01:00

Create a program named Reverse3 whose Main () method declares three integers named firstInt, middleInt, and lastInt. Assign the following values to the integers: 23 to firstInt 45 to middleInt 67 to lastInt Then display the values and pass them to a method named Reverse that accepts them as reference variables, places the first value in the lastInt variable, and places the last value in the firstInt variable.

+3
Answers (1)
  1. 11 April, 04:40
    0
    This question is incomplete. The complete question is given below:

    Create a C# Console program named Reverse3 whose Main () method declares three integers named firstInt, middleInt, and lastInt.

    Assign the following values to the integers:

    23 to firstInt

    45 to middleInt

    67 to lastInt

    Then display the values and pass them to a method named Reverse that accepts them as reference variables, places the first value in the lastIntvariable, and places the last value in the firstInt variable.

    In the Main () method, display the three variables again, demonstrating that their positions have been reversed.

    using static System. Console;

    class Reverse3

    {

    static void Main ()

    {

    / / Write your main here

    }

    public static void Reverse (ref int a, ref int b, ref int c)

    {

    }

    }

    Answer:

    using static System. Console;

    class Reverse3

    {

    static void Main ()

    {

    int firstInt = 23;

    int middleInt = 45;

    int lastInt = 67;

    Console. WriteLine ("Before reversing: firstInt: " + firstInt + ", middleInt: " + middleInt + ", lastInt: " + lastInt);

    Reverse (ref firstInt, ref middleInt, ref lastInt);

    Console. WriteLine ("After reversing: firstInt: " + firstInt + ", middleInt: " + middleInt + ", lastInt: " + lastInt);

    }

    public static void Reverse (ref int a, ref int b, ref int c)

    {

    int temp = c;

    c = a;

    a = temp;

    }

    }

    Explanation:

    Inside the main () method, initialize the variables firstInt, middleInt, lastInt with 23, 45 and 67 respectively. Then print the values of all these variables on the console. Call the Reverse method and pass these variables as references. Print the updated values of all these variables on the console.

    Inside the Reverse method, swap the values of firstInt with the lastInt by initializing the temp variable with c.

    Output:

    Before reversing: firstInt: 23, middleInt: 45, lastInt: 67

    After reversing: firstInt: 67, middleInt: 45, lastInt: 23
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Create a program named Reverse3 whose Main () method declares three integers named firstInt, middleInt, and lastInt. Assign the following ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers