Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a method compare that compare two arrays of int values. Your method should

ID: 3680534 • Letter: W

Question

Write a method compare that compare two arrays of int values. Your method should take two int arrays as parameters. It should return true if the two arrays are of the same length and contain the same values in the same order. Otherwise it should return false. (Do not call any methods that come built-in to Java.) If a = {1, 2, 3, 4} and b = {1, 2, 3, 4}, calling compare(a, b) should return true If a = {1, 2, 3, 4} and b = {1, 2, 3, 4, 5}, calling compare(a, b) should return false If a = {1, 2, 3, 4} and b = {1, 2, 3, 4}, calling compare(a, b) should return false

Explanation / Answer

using System; class CompareTwoCharArray { private static void Main() { char[] firstArray = {'1', '2', '3', '4'}; int firstArrayLength = firstArray.Length; char[] secondArray = {'1', '2', '3', '4'}; int secondArrayLength = secondArray.Length; int length = Math.Min(firstArray.Length, secondArray.Length); if (firstArray.Length > secondArray.Length) { Console.WriteLine("Second array is earlier."); } else if (firstArray.Length == secondArray.Length) { for (int i = 0; i secondArray[i]) { Console.WriteLine("false.array are not equal"); break; } else if (secondArray[i] > firstArray[i]) { Console.WriteLine(“false aaray are not equal."); break; } else { Console.WriteLine("Two arrays are equal."); } } } else { Console.WriteLine("First array is earlier."); } } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote