Question

I need help with some java code concerning the comparison of two arrays. Let's say I...

I need help with some java code concerning the comparison of two arrays.

Let's say I have two arrays. Array A and Array B. Array A has 7 integers on each line, and there are hundreds of lines. Array B is the same as Array A except every line of integers have been sorted in ascending order. In Array A there are already lines that are sorted, so some lines in Array A will be equal in Array B. What code could I write to I find out which lines in the arrays are equal and print only those lines out using the Arrays.equals method in java?

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

public class Array_equals

{

//Takes Array A and B and their size as rowA,rowB and column size as size

public static void Compare(int[][] A,int [][] B,int rowA,int rowB,int size)

{

//for each row in array A

for(int i=0;i<rowA;i++)

{

//for each row in array B

for(int j=0;j<rowB;j++)

{

//check is a flag, it is true

//only when all the elements are equal

boolean check=true;

//checking all the elements are equal or not

for(int k=0;k<size;k++)

{

if(A[i][k]!=B[j][k])

{

check=false;

break;

}

}

//if equal,print row number of A

if(check)

System.out.println(i);

}

}

}

//main method

public static void main(String args[])

{

//for simplisity, i passed only less size of arrays

int[][] arr1={{1,2,3},{2,3,4}};

int[][] arr2={{2,3,4},{3,4,5}};

Compare(arr1,arr2,2,2,3);

}

}

Add a comment
Know the answer?
Add Answer to:
I need help with some java code concerning the comparison of two arrays. Let's say I...
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
  • Write a JAVA Program: Compare the performance of bubble sort and selection sort over several arrays....

    Write a JAVA Program: Compare the performance of bubble sort and selection sort over several arrays. - Write two methods that sort arrays of doubles. One method should use selection sort, and the other should use bubble sort. - In each of the sort methods, add code that counts the total number of comparisons and total number of swaps performed while sorting the entire array (be careful; don't count each pass through the array separately) - Each time an array...

  • Write a java program to sort arrays using 3 different methods: Bubble Sort, Selection Sort and...

    Write a java program to sort arrays using 3 different methods: Bubble Sort, Selection Sort and Insertion Sort. The numbers to be sorted will be obtained using a library function which generates pseudo-random numbers. TO Do 1. Fill an array with 140 real numbers between 0.00 and 945.00. Generate the numbers using the subroutine that generates random numbers. Make a spare copy of the array; you will need it later. 2. Call a subroutine to print the contents of the...

  • This is for JAVA programming. Create a test class that contains two arrays and two methods:...

    This is for JAVA programming. Create a test class that contains two arrays and two methods: - The first array has 3 rows and 3 columns and is initialized with type double data - The second array has 4 rows and 4 columns and is also initialized with type double data - The first method ArraysRows will receive an array of type double as an argument and then print out the sum and average of all elements in each ROW....

  • Suppose we have two integer arrays with the same type, write an AL program to check...

    Suppose we have two integer arrays with the same type, write an AL program to check whether or not there are two integers, one from each array, with sum equal to zero. If there are such integers exist, print out all such combinations to the console window, otherise, print out "No integers in these two arrays, one from each array, with sum equal to zero." to the console window. December 3. 2018 For example, suppose we have the following two...

  • how do i do this in basic java without using hashmat or anything complicated Two-Dimensional Arrays....

    how do i do this in basic java without using hashmat or anything complicated Two-Dimensional Arrays. Write the three functions described below. Demonstrate that your code works by calling each function and printing out the results. All of your code should be in one file. Upload your java code and a file containing the output of running your program to show that it works. Write a function called create2DIntArray that creates a two-dimensional array of integers between 0 and 10....

  • Java arrays Create method named repeatedN that takes two integer parameters named range and n and...

    Java arrays Create method named repeatedN that takes two integer parameters named range and n and returns an integer array Method should return an integer array that has numbers 0 - range repeated in order n times If range is less than or equal to 0; return an array that has 0 repeated n times Create a second method named printArray that takes an integer array as a parameter. The method should print out every element on the same line...

  • Hi, I need help with my comp sci assignment. The parameters are listed below, but I...

    Hi, I need help with my comp sci assignment. The parameters are listed below, but I am having trouble generating the number of occurrences of each word. Please use a standard library. Read in the clean text you generated in part 2 (start a new cpp file). Create a list of all the unique words found in the entire text file (use cleanedTextTest.txt for testing). Your list should be in the form of an array of structs, where each struct...

  • I need help in java use anythitg except​ (Method , bollean ) Given nA and a[0],...

    I need help in java use anythitg except​ (Method , bollean ) Given nA and a[0], a[1], ..., a[nA - 1], give a segment of code that will copy the non-zero elements of array "a" into an array "b", "squeezing out the zeroes", and setting nB equal to the number of non-zero elements in b. That is, if nA=13 and the contents of a[i], where i = 0 to nA - 1 are initially 0.0, 1.2, 0.0, 0.0, 0.0, 2.3,...

  • I need help parsing a large text file in order to create a map using Java....

    I need help parsing a large text file in order to create a map using Java. I have a text file named weather_report.txt which is filled with hundreds of different indexes. For example: one line is "POMONA SUNNY 49 29 46 NE3 30.46F". There are a few hundred more indexes like that line with different values in the text file and they are not delimited by commas but instead by spaces. Therefore, in this list of indexes we only care...

  • *Java* Hi. I need some help with creating generic methods in Java. Write a program GenMethods...

    *Java* Hi. I need some help with creating generic methods in Java. Write a program GenMethods that has the following generic methods: (1) Write the following method that returns a new ArrayList. The new list contains the nonduplicate (i.e., distinct) elements from the original list. public static ArrayList removeDuplicates(ArrayList list) (2) Write the following method that shuffles an ArrayList. It should do this specifically by swapping two indexes determined by the use of the random class (use Random rand =...

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