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?
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);
}
}
I need help with some java code concerning the comparison of two arrays. Let's say I...
I need help with this .java implementation: Implement an algorithm that given two sorted arrays of size m and n creates a sorted array of size (n + m) in O(n + m) time. The script must take as an input a command line argument specifying the name of a .txt file which will contain the arrays to be sorted. Each line in the .txt file will contain two arrays, with elements in arrays separated by commas and the 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 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...
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...
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....
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....
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,...
Java programming question: Here is the feedback I received "sort fails. Use Arrays class method to sort." The actual question: Write a program as follows: Declare a five element array of Strings. Use a for loop and keyboard input to populate the array with the names of five friends. Sort the array in alphabetical order. Use a foreach loop to print the sorted array of friends, all on one line. Sample Output (inputs in italics) Enter the names of five...
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 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 =...