Question
ON CENGAGE MINDTAP Create a program named FlexibleArrayMethod that declares at least three integer arrays of different sizes. In turn, pass each array to a
ON CENGAGE MINDTAP Create a program named FlexibleArrayMethod that declares at least three integer arrays of different sizes. In turn, pass each array to a method named DisplayAndSum that displays all the integers in each array and their sum. C# language
This is my code and it is saying it is wrong. \
using System;
public class FlexibleArrayMethod
{
public static void Main()
{
int[] arr1 = {3, 9, 1};
int[] arr2 = {98, 89, 81, 85};
int[] arr3 = {-3, -8, 9, 2, 6, -7};
DisplayAndSum(arr1);
DisplayAndSum(arr2);
DisplayAndSum(arr3);
}
public static void DisplayAndSum(int[] arr)
{
double total = 0;
Console.Write("Array is: {0}");
for(int i = 0; i < arr.Length; i++) {
total += arr[i];
Console.Write(arr[i] + " ");
}
double average = total / arr.Length;
Console.WriteLine("Average is {0}" + average);
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started