cherokee

C# Part 2 - Arrays - Exercise 2

Jan 5th, 2013
27
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2.  
  3. class CompareTwoArrays
  4. {
  5.     static void Main()
  6.     {
  7.         // Write a program that reads two arrays from the console and compares them element by element.
  8.         Console.Title = "Compare two arrays for equality";
  9.         Console.WriteLine("Array 1 - Enter values on one line separated by space: ");
  10.         string[] arrayOne = Console.ReadLine().Split();
  11.         Console.WriteLine("Array 2 - Enter values on one line separated by space: ");
  12.         string[] arrayTwo = Console.ReadLine().Split();
  13.         if (arrayOne.Length != arrayTwo.Length)
  14.         {
  15.             Console.WriteLine("Your arrays are with different sizes, so they can not be equal!");
  16.         }
  17.         else
  18.         {
  19.             bool[] equalsArray = new bool[arrayOne.Length];
  20.             Console.WriteLine("{0,10}{1,10}{2,10}", "Array 1", "Array 2", "Equal?");
  21.             Console.WriteLine(new string('-', 30));
  22.             for (int i = 0; i < arrayOne.Length; i++)
  23.             {
  24.                 if (arrayOne[i] == arrayTwo[i])
  25.                 {
  26.                     equalsArray[i] = true;
  27.                 }
  28.                 Console.WriteLine("{0,8}{1,10}{2,11}", arrayOne[i], arrayTwo[i], equalsArray[i]);
  29.             }
  30.         }
  31.     }
  32. }
RAW Paste Data