0% found this document useful (0 votes)
2 views3 pages

2D Array Methods for Java Programming

Uploaded by

morajirathi741
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

2D Array Methods for Java Programming

Uploaded by

morajirathi741
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

package arrays;

/*
* HW-2D arrays, For this assignment you need to write and test code for
* each of the following methods. Make sure to test code for each method as
* you are working through these methods. This will be a graded assessment.
* Please make sure to email yourself this code as you will be using this
* code in order to do next set of programs.
*/
public class Arrays2DAssignment {

// Use this method to keep testing every method as you write them.
public static void main(String[] args) {

/*
* #1 This method will initialize N in row major order with the integer
* values in the range start-end inclusive.
* Precondition: end is greater than start
*/
public static void initRow(int[][] N, int start, int end) {

/*
* #2 This method will initialize N in column major order with the integer
* values in range start-end inclusive.
* Precondition: end is greater than start
*/
public static void initColumn(int[][] N, int start, int end) {

/*
* #3 Outputs N in row by column format, with all row elements on the same
* line separated by [Link]
* 2 4 7
* 4 7 0
*/
public static void output2D(int[][] N) {

/*
* #4 Returns an int array of size [Link]. Each element of this array will
* represent the sum of all the elements of the corresponding row of the 2D
* input array N.
*/
public static int[] sumRow(int[][] N) {
int[] rowSum = new int[[Link]];

return rowSum;
}

/*
* #5 Returns an int array of size N[0].length. Each element of this array
* will represent the sum of all the elements of corresponding column of the
* 2D input array N.
*/
public static int[] sumCol(int[][] N) {
int[] colSum = new int[N[0].length];

return colSum;
}

/*
* #6 sumRC will return sum of all of the elements of row or column as
* determined by rc, located at the location determined by index.
*/
public static int sumRC(int[][] N, char rc, int index) {
int sum = 0;
if (rc == 'C') {

} else if (rc == 'R') {

return sum;
}

/*
* #7 Returns total number of elements in the 2D whose value is above val.
*/
public static int countElementsAbove(int[][] N, int val) {
int count = 0;

return count;
}

/*
* #8 Converts 2D array to 1D, filling one row at a time going from left to
* right
*/
public static int[] convert2Dto1DRowMajor(int[][] N) {

return new int[0]; // replace this statement with you own


}

/*
* #9 Converts 2D array to 1D, filling from one column at a time going from
* top to bottom
*/
public static int[] convert2Dto1DColumnMajor(int[][] N) {

return new int[0]; // replace this statement with you own


}

/*
* #10 Converts 2D array to 1D, filling rows continuously. First going from
* left to right, then right to left and then repeating the same pattern
* over and over
*/
public static int[] convert2Dto1DContinousRow(int[][] N) {

return new int[0]; // replace this statement with you own


}
/*
* #11 Converts 2D array to 1D, filling columns continuously. First going
* from top to bottom of the first column, then bottom to top of second
* column and then from top to bottom of the 3rd Column
*/
public static int[] convert2Dto1DContinousColumn(int[][] N) {

return new int[0]; // replace this statement with you own


}

/*
* #12 This method receives an 2D int array and returns a 1D array of size
* 2, representing the index of the minimum value found in this array.
* minI[0]->row, minI[1] -> column.
*/
public static int[] findMinIndex(int[][] N) {
int[] minI = new int[2];

return minI;
}

/*
* #13 This method swaps the element stored at loc1 with the element stored
* at loc2 in N array.
*/
public static void swap(int[][] N, int[] loc1, int[] loc2) {

You might also like