JAVA
Write a method to copy contents in a two-dimensional array to a one-dimensional array. The method will return this one-dimensional array.
Method is declared as below:
public static double [] copyArray (float [][] m);
TEST METHOD in main().
please find an output screenshot along with the code.
filename : ArrayConversion.java
code :
//our package name starts here
package com.practice.HomeworkLib;
//importing the libraries
import java.util.ArrayList;
//our class starts here
public class ArrayConversion {
//method starts here
public static ArrayList<Double> copyArray(float
[][] m){
//defining an arraylist here
ArrayList<Double> list = new
ArrayList<Double>();
//iterating through 2 dimensional
array
//through rows
for(int
i=0;i<m.length;i++){
//through
columns
for(int
j=0;j<m[i].length;j++){
//adding into list
list.add((double) m[i][j]);
}
}
//returning the list
return list;
}
//main method starts here
public static void main(String[] args) {
// TODO Auto-generated method
stub
//initializing the variables
float[][] arr = new
float[3][3];
float temp = (float) 12.5;
//iterating through rows
for(int i=0;i<3;i++){
//iterating
through columns
for(int
j=0;j<3;j++){
//storing in ana array
arr[i][j] = temp + (i+j+1);
}
}
//storing result in an
arraylist
ArrayList<Double> list =
copyArray(arr);
//printing the output
for(int
i=0;i<list.size();i++){
System.out.println("Element in position " + i + " is "+
list.get(i));
}
}
}
output screenshot :

JAVA Write a method to copy contents in a two-dimensional array to a one-dimensional array. The...
Define a two-dimensional int array which has 5 rows and 3 columns. The elements in array is randomly initialized (using Math.random()). Write a method to find the maximum value in this two dimensional array; Write a method to find the average value in the array; Write a method to count how many elements are smaller than average; Write a method to copy contents in a two-dimensional array to a one-dimensional array. The method will return this one-dimensional array. Method is...
Write in Java (10 pts) Write a public method named “Even_Sum” that accepts a one-dimensional array of integers and returns the sum of the even elements in the array (10 pts) Write a public method named “Reverse” that receives a string prints its contents in reverse to the standard output using a stack. Assume the stack has been created and is empty.
1.Write code for a Java method, printArray, that takes an int array as parameter and prints it out, one element per line. public static void printArray (int[] values){ Methods that do NOT return a result have “void” as return type. Notice how an array parameter type is passed, int [] }// end printArray 2.Write code for a Java method that takes in as input parameter an integer number, say num, and returns a double array of size num with all...
JAVA Write a static method that takes an array of a generic type as its only argument. The method should display the array and return the number of elements in the array. Test the method in main with at least three arrays of objects. SAMPLE OUTPUT Here is an Integer array 12 21 7 16 8 13 That array held 6 elements Here is a String array one two three four That array held 4 elements Here is a Double...
In java, write method, shuffle, which accepts an array of int, creates a copy of the formal parameter, shuffles the copy, then returns the copied, shuffled array, leaving the formal parameter unchanged. Shuffling is a process of swapping each element of array with another element randomly chosen from the array. For testing the shuffle method have main call shuffle, repeatedly having it shuffle its previously returned array until the returned (shuffled) array is identical (equal) to the original array that...
Question 1[JAVA] Add a method in the Main class named getLines() that takes a filename as a String and returns each line in the file in an array. Have each element of the array be a String. Do not include the newline at the end of each line. Use a BufferedReader object to read the file contents. Note, the contents of input.txt will be different (including the number of lines) for each test case. Example: getLines( "input.txt" ) returns (an...
Create a new public static method called ‘isLatinSquare’ that passes in a two-dimensional array. This new method will return ‘true’ if the passed array is a Latin Square. isLatinSquare(int[][]) should be one or two lines of code
Write a java Program Initialize Array. Write a Java method initArray() with the following header to initialize a one-dimensional array a such that the element values (integers) are twice the index value. For example, if i = 23, then a23 = 46. The function is void with one parameter -- the integer array of a[]. Then write a main() with an int[] array2i size 100 to call
(JAVA) Write a program that maintains student test scores in a two-dimesnional array, with the students identified by rows and test scores identified by columns. Ask the user for the number of students and for the number of tests (which will be the size of the two-dimensional array). Populate the array with user input (with numbers in {0, 100} for test scores). Assume that a score >= 60 is a pass for the below. Then, write methods for: Computing the...
Write a java program that has a method called sameArrayBackwards. The method takes an array of integers, and checks if the numbers in the array are the same going forward as going backwards and will return a boolean (true or false) depending on the result. You can assume that there is at least one element in the array. Method Header: public static boolean sameArrayBackwards (int [] arr) You will test your method in the main method of your program by...