subject

This question involves reasoning about arrays of integers. You will write methods in a class named ArrayTester. Write a static method getColumn, which returns a one-dimensional array containing the elements of a single column in a two-dimensional array. The elements in the returned array should be in the same order as they appear in the given column. The notation arr2D [r] [c] represents the array element at row r and column c.
The following code segment initializes an array and calls the getColumn method.
int [] [] arr2D = { {
0,
1,
2
},
{
3,
4,
5
},
{
6,
7,
8
},
{
9,
5,
3
} };
int [] result = ArrayTester. getColumn (arr2D, 1);
When the code segment has completed execution, the variable result will have the following contents.
result: {1, 4, 7, 5}
Write a static method getRow, which returns a one-dimensional array containing the elements of a single row in a two-dimensional array. The elements in the returned array should be in the same order as they appear in the given row. The notation arr2D [r] [c] represents the array element at row r and column c.
int [] result = ArrayTester. getRow (arr2D, 1);
When the code segment has completed execution, the variable result will have the following contents.
result: {3, 4, 5}
Complete these two methods in the program:
hasAllValues
containsDuplicates
Write the static method isLatin, which returns true if a given two-dimensional square array is a Latin square, and otherwise, returns false.
A two-dimensional square array of integers is a Latin square if the following conditions are true.
The first row has no duplicate values. Must use method containsDuplicates in part 3.
All values in the first row of the square appear in each row of the square. Must use hasAllValues in part 3.
All values in the first row of the square appear in each column of the square. Must use hasAllValues in part 3.
This is the given code:
import java. util. Arrays;
public class ArrayTester
{
/** Returns an array containing the elements of column c of arr2D in the same order as they appear in arr2D.
* Precondition: c is a valid column index in arr2D.
* Postcondition: arr2D is unchanged.
*/
public static int [] getColumn(int [][] arr2D, int c)
{
/* your code */
}
/** Returns an array containing the elements of row c of arr2D in the same order as they appear in arr2D.
* Precondition: r is a valid column index in arr2D.
* Postcondition: arr2D is unchanged.
*/
public static int [] getRow(int [][] arr2D, int c)
{
/* your code */
}
/** Returns true if and only if every value in arr1 appears in arr2.
* Precondition: arr1 and arr2 have the same length.
* Postcondition: arr1 and arr2 are unchanged.
*/
public static boolean hasAllValues(int [] arr1, int [] arr2)
{
/* your code */
}
/** Returns true if arr contains any duplicate values;
* false otherwise.
*/
public static boolean containsDuplicates(int[] arr)
{
/* your code */
}
/** Returns true if square is a Latin square ; false otherwise.
* Precondition: square has an equal number of rows and columns.
* square has at least one row.
*/
public static boolean isLatin(int[][] square)
{
/* your code */
}
/ Test /
public static void main(String[] args)
{
int [] [] arr2D = { {0, 1, 2}, {3, 4, 5}, {6, 7, 8}, {9, 5, 3} };
int [] result = ArrayTester. getColumn (arr2D, 1);
System. out. println(Arrays. toString (result));
int [] result = ArrayTester. getColumn (arr2D, 1);
System. out. println(Arrays. toString (result));
int [] [] square1 = { {1, 2, 3}, {2, 3, 1}, {3, 1, 2} };
int [] [] square2 = { {10, 30, 20, 0}, {0, 20, 30, 10}, {30, 0, 10, 20}, {20, 10, 0, 30} };
int [] [] square3 = { {1, 2, 1}, {2, 1, 1}, {1, 1, 2} };
int [] [] square4 = { {1, 2, 3}, {3, 1, 2}, {7, 8, 9} };
int [] [] square5 = { {1, 2}, {1, 2}};
System. out. println(isLatin (arr2D) + " " + isLatin (square1) + " " + isLatin (square2) + " " +
isLatin (square3) + " " + isLatin (square4) + " " + isLatin (square5));
}
}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 16:00
Ramon is graphing the function  f(x) = 3(4)x. he begins by plotting the initial value. which graph represents his initial step?
Answers: 2
question
Computers and Technology, 22.06.2019 18:00
Which of the following physical laws can make the flow of water seem more realistic? a. motion b. gravity c. fluid dynamics d. thermodynamics
Answers: 2
question
Computers and Technology, 22.06.2019 22:30
You are new to microsoft certification and want to start out by getting a certification geared around windows 8. what microsoft certification should you pursue?
Answers: 1
question
Computers and Technology, 23.06.2019 09:30
Write a function called checkfactor that takes two arrays of positive numbers, firstnumberrow and secondnumberrow. checkfactor checks if the first entry in firstnumberrow is divisible by the first entry in secondnumberrow, and performs the same operation on the next array elements until all entries have been checked. all the numbers are positive and the number of entries in the arrays are the same. the function should return the identified divisible numbers in two row arrays named firstdivisible and seconddivisible.restrictions: branches or loops should not be used. the code must use the internal mod and logical functions.hint: the mod function should be used to determine if two numbers are divisible. ex: for num1 and num2 if mod(num1,num2) is 0, then the two numbers are divisible.this is matlab
Answers: 2
You know the right answer?
This question involves reasoning about arrays of integers. You will write methods in a class named A...
Questions
question
Mathematics, 05.02.2020 00:49
question
Mathematics, 05.02.2020 00:49
question
Mathematics, 05.02.2020 00:49
Questions on the website: 13722363