Question

Note: According to the question, please write source code in java only using the class method. Sample Run (output) should be the same as displayed in the question below. Make sure the source code is working properly and no errors.

Exercise #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 returns false. The program main method calls method compare () and prints the result from the method as shown below. Document your code and organized your output following these sample runs Sample run 1: Array size: First array: Second array: Judgment: 23, -45, 78, 10 23, -45, 78, 10 The arrays are identical Sample run 2: Array size: First array: Second array: Judgment: 78, 128, 300, 12, 300 78, 128, 12, 300, 300 The arrays are not identical Sample run 3: Array size: First array: Second array: Judgment: 1 The arrays are identical

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

Here is the java program and output of the same. In case of any query do write in the comments.

CompareArrays.java
*******************************************************************************

import java.util.Scanner;

public class CompareArrays

{
//Method Compare(array1, array2) , returns true if both the arrays are equal

static boolean Compare(int []arr1, int []arr2 ){

boolean flag = true;

for(int j=0; j

if( arr1[j] != arr2[j] ){

flag = false;

return flag;

}

}

return flag;

  

}

public static void main(String[] args) {

System.out.print("Array size: ");

Scanner sc = new Scanner(System.in);

int size = sc.nextInt();

sc.nextLine();

int array1[] = new int[size];

int array2[] = new int[size];

System.out.print("First array: ");

Scanner input1 = new Scanner(System.in); //Take console input for populating the array here

for(int i=0; i

array1[i] = input1.nextInt();   

}

System.out.print("Second array: ");

Scanner input2 = new Scanner(System.in);

for(int i=0; i

array2[i] = input2.nextInt();

}

  

if(Compare( array1, array2 )){

System.out.println("Judgement: The arrays are identical");

}

else

System.out.println("Judgement: The arrays are not identical");

}

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Output:

Array size: 5 First array: 78 128 300 12 300 Second array: 78 128 12 300 300 Judgement: The arrays are not identical

Add a comment
Know the answer?
Add Answer to:
Note: According to the question, please write source code in java only using the class method....
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
  • PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE INTO VISUAL STUDIO Exercise #2:...

    PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE INTO VISUAL STUDIO Exercise #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...

  • SOLVE IN PYTHON: Exercise #2: Design and implement a program (name it CompareArrays) that compares the...

    SOLVE IN PYTHON: Exercise #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...

  • 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...

  • C++ Single Dimensional Arrays

    Exercise #1: Design and implement a program (name it AssignGrades) that stores and processes numeric scores for a class. The program prompts the users to enter the class size (number of students) to create a single-dimensional array of that size to store the scores. The program prompts the user to enter a valid integer score (between 0 and 100) for each student. The program validates entered scores, rejects invalid scores, and stores only valid scores in the array.  The program...

  • IN PYTHON WITHOUT USING: .APPEND/ .SORT/ INSERT / .SPLIT Program 1: Design (pseudocode) and implement (source...

    IN PYTHON WITHOUT USING: .APPEND/ .SORT/ INSERT / .SPLIT Program 1: Design (pseudocode) and implement (source code) a program (name it Occurrences) to determine whether two two-dimensional arrays are equivalent or not. Two arrays are equivalent if they contain the same values in any order. The program main method defines two two-dimensional array of size 3-by-3 of type integer, and prompts the user to enter integer values to initialize the arrays. The main method calls method isEquivalent()that takes two two-dimensional...

  • In pseudocode only Design (pseudocode) a program (name it Occurrences) to determine whether two two-dimensional arrays...

    In pseudocode only Design (pseudocode) a program (name it Occurrences) to determine whether two two-dimensional arrays are equivalent or not. Two arrays are equivalent if they contain the same values in any order. The program main method defines two two-dimensional array of size 3-by-3 of type integer, and prompts the user to enter integer values to initialize the arrays. The main method calls method isEquivalent()that takes two two-dimensional arrays of integer and returns true (boolean value) if the arrays contain...

  • C# ONLY INCLUDE BOTH PSUDEO CODE AND SOURCE CODE!!!! Design (pseudocode) and implement (source code) a...

    C# ONLY INCLUDE BOTH PSUDEO CODE AND SOURCE CODE!!!! Design (pseudocode) and implement (source code) a program (name it IndexOfLargest) to find the index of the first largest value in the array. Note that the largest value may appear more than once in the array. The program main method defines a single-dimensional array of size 10 elements and prompts the user to enter 10 integers to initialize the array. The main method then calls method findIndex() that takes a single-dimensional...

  • Note: According to the question, please write source code in java only using the class method....

    Note: According to the question, please write source code in java only using the class method. Sample Run (output) should be the same as displayed in the question below. Make sure the source code is working properly and no errors.​ Exercise #2: Design and implement class Radio to represent a radio object. The class defines the following attributes (variables) and methods Assume that the station and volume settings range from 1 to 10 1. A private variable of type int...

  • PLEASE DO THE PSEUDOCODE FOR THE PROGRAM BELOW Program 3: Design (pseudocode) and implement (source code)...

    PLEASE DO THE PSEUDOCODE FOR THE PROGRAM BELOW Program 3: Design (pseudocode) and implement (source code) a program (name it DistinctValues) to display only district values in an array. The program main method defines a single-dimensional array of size 10 elements and prompts the user to enter 10 integers to initialize the array. The main method then calls method getValues() that takes an integer array and returns another single-dimensional array containing only distinct values in the original (passed) array. Document...

  • Please solve only if you know how to do it. Write the code using C++ (not...

    Please solve only if you know how to do it. Write the code using C++ (not Python or Java). Show and explain everything neatly. COMMENTS (7.5% of programming assignment grade): Your program should have at least ten (10) different detailed comments explaining the different parts of your program. Each individual comment should be, at a minimum, a sentence explaining a particular part of your code. You should make each comment as detailed as necessary to fully explain your code. You...

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