logo CodeStepByStep logo

ArrayMysteryExam2

Language/Type: C# arrays

Write the output produced by the following method when passed each of the following arrays:

public static void ArrayMysteryExam2(int[] a)
{
    for (int i = 0; i < a.Length - 1; i++)
    {
        if (a[i] > a[i + 1])
        {
            int temp = a[i];
            a[i] = a[i + 1];
            a[i + 1] = temp;
            a[0]++;
        }
    }
    Console.WriteLine(a);
}
{5, 2, 5, 2}
{30, 10, 20, 50, 40}
{99, 88, 77, 66, 55, 44}

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.