Question

Create a C# console application that performs the following: 1) Build a method which reads 3...

Create a C# console application that performs the following:

1) Build a method which reads 3 integers from the console and returns them as an int array (type a number, then hit enter, 3 times). This needs to be its own method.

2) Call this method twice to store 2 local int array variables.

3) Once both arrays are built, write another method which accepts the two arrays and compares the contents to see if they match. If the method returns true (the arrays match), display "Arrays match" in the console. Otherwise, display "Arrays don't match" in the console. 4) Finally, ensure at the end, that the user must hit the enter key in order to exit the program.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I HOPE ITS HELPFULL TO YOU ...IF YOU HAVE ANY DOUBTS PLS COMMENTS BELOW...I WILL BE THERE TO HELP YOU...PLS RATE THUMBS UP...!!

ANSWER::-

as for given data..

Create a C# console application that performs the following:

1) Build a method which reads 3 integers from the console and returns them as an int array (type a number, then hit enter, 3 times). This needs to be its own method.

2) Call this method twice to store 2 local int array variables.

3) Once both arrays are built, write another method which accepts the two arrays and compares the contents to see if they match. If the method returns true (the arrays match), display "Arrays match" in the console. Otherwise, display "Arrays don't match" in the console. 4) Finally, ensure at the end, that the user must hit the enter key in order to exit the program.

CODE ::-

using System;

public class Test
{
   public static void Main()
   {
       int[] array1 = new int[3];
       array1 = input(); // call to input() function to input elements of array1
      
       int[] array2 = new int[3];
       array2 = input();// call to input() function to input elements of array1
      
       if(compare(array1,array2) == true) // compare two arrays
       Console.WriteLine("Arrays match");
       else
       Console.WriteLine("Arrays don't match");
      
       Console.Read();


      
      
   }
   public static int[] input()
   {
       int[] array = new int[3];
       for(int i = 0;i<3;i++)
       {
           Console.WriteLine("Enter an integer : ");
           int x = Convert.ToInt32(Console.ReadLine());
          
           array[i] = x;
       }
       return array;
   }
  
   public static bool compare(int[] array1,int[] array2)
   {
       bool flag = true;
       for(int i=0;i<3;i++)
       {
           if(array1[i] != array2[i]) // if any of the element of two arrays is not same flag = false
           flag = false;
       }
      
       return flag;
   }
}

Output:

Enter an integer : 4

Enter an integer :5

Enter an integer :6

Enter an integer :4

Enter an integer :5

Enter an integer :3

Arrays don't match

THANK YOU....!!

Add a comment
Know the answer?
Add Answer to:
Create a C# console application that performs the following: 1) Build a method which reads 3...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a C# console application that performs the following: 1) Build a method which reads 3...

    Create a C# console application that performs the following: 1) Build a method which reads 3 integers from the console and returns them as an int array (type a number, then hit enter, 3 times). This needs to be its own method. 2) Call this method twice to store 2 local int array variables. 3) Once both arrays are built, write another method which accepts the two arrays and compares the contents to see if they match. If the method...

  • 3. Write Java methods to accomplish each of the following Write a method named simpleAry which...

    3. Write Java methods to accomplish each of the following Write a method named simpleAry which accepts and return nothing. It creates an array that can hold ten integers. Fill up each slot of the array with the number 113. Then, display the contents of the array on the screen. You must use a loop to put the values in the array and also to display them. Write a method named sury which accepts an array of type double with...

  • JAVA HELP (ARRAYS) Assignment Create a class named Module4 containing the following data members and methods...

    JAVA HELP (ARRAYS) Assignment Create a class named Module4 containing the following data members and methods (note that all data members and methods are for objects unless specified as being for the entire class) 1) Data members: none 2) Methods a. A method named displayContents that accepts an array of type int and prints their values to the b. A method named cemoveNegatives that accepts an array of type int, copies all its non-negative the new array should be the...

  • . In the method main, prompt the user for a non-negative integer and store it in...

    . In the method main, prompt the user for a non-negative integer and store it in an int variable num (Data validation is not required for the lab). Create an int array whose size equals num+10. Initialize the array with random integers between 0 and 50 (including 0 and excluding 50). Hint: See Topic 4 Decision Structures and File IO slides page 42 for how to generate a random integer between 0 (inclusive) and bound (exclusive) by using bound in...

  • C++ Arrays & Methods

     #2: Design and implement a program (name it CompareArrays) that compares the content of 2 single-dimensional arrays of the same size. The program prompts the users to enter the array size. Then prompts the user to initialize each array with integer values. The program defines method Compare() that takes two signal-dimensional arrays of type integer. The method compares the content of the arrays and returns true (Boolean type) if the arrays store same values in the same order. Otherwise, it...

  • Write a Lottery class that simulates a 6-number lottery (e.g. "Lotto"). The class should have an...

    Write a Lottery class that simulates a 6-number lottery (e.g. "Lotto"). The class should have an array of six integers named lotteryNumbers, and another array of six integers named userLotteryPicks. The class' constructor should use the Random class to generate a unique random number in the range of 1 to 60 for each of the 6 elements in the lotteryNumbers array. Thus, there should be a loop that keeps generating random numbers until all 6 numbers are unique.  The Lottery class...

  • (2 bookmarks) In JAVA You have been asked to write a program that can manage candidates...

    (2 bookmarks) In JAVA You have been asked to write a program that can manage candidates for an upcoming election. This program needs to allow the user to enter candidates and then record votes as they come in and then calculate results and determine the winner. This program will have three classes: Candidate, Results and ElectionApp Candidate Class: This class records the information for each candidate that is running for office. Instance variables: first name last name office they are...

  • Using Arrays with Sorting and Searching Algorithms 1) This program has six required outputs and involves...

    Using Arrays with Sorting and Searching Algorithms 1) This program has six required outputs and involves searching and sorting an array of integers. Write a java application that initializes an array with the following numbers, in this order: 23, 17, 5, 90, 12, 44, 38, 84, 77, 3, 66, 55, 1, 19, 37, 88, 8, 97, 25, 50, 75, 61, and 49. Then display the unsorted values. This is required output #1 of 6 for this program. 2) Using a...

  • For the following C# program: Let’s add one more user defined method to the program. This...

    For the following C# program: Let’s add one more user defined method to the program. This method, called ReverseDump is to output the values in the array in revere order (please note that you are NOT to use the Array.Reverse method from the Array class). The approach is quite simple: your ReverseDump method will look very similar to the Dump method with the exception that the for loop will count backwards from num 1 to 0 . The method header...

  • IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are...

    IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are developing a program that works with arrays of integers, and you find that you frequently need to duplicate the arrays. Rather than rewriting the array-duplicating code each time you need it, you decide to write a function that accepts an array and its size as arguments. Creates a new array that is a copy of the argument array, and returns a pointer to the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT