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, 22.06.2019 10:20
Print "usernum1 is negative." if usernum1 is less than 0. end with newline. convert usernum2 to 0 if usernum2 is greater than 10. otherwise, print "usernum2 is less than or equal to 10.". end with newline
Answers: 3
question
Computers and Technology, 23.06.2019 00:50
Representa os dados de um banco de dados como uma coleç? o de tabelas constituídas por um conjunto de atributos, que definem as propriedades ou características relevantes da entidade que representam. marque a alternativa que representa o modelo descrito no enunciado. escolha uma:
Answers: 3
question
Computers and Technology, 23.06.2019 09:30
After you present a proposal, the committee starts asking you questions, some beyond the strict focus of your proposal. they ask questions about implications in other fields and knowledge about other fields. you are asked to redo your proposal. what is most likely missing? breadth of material depth of material clarity of material details of material
Answers: 1
question
Computers and Technology, 23.06.2019 18:30
The computers in the sales department did not have enough data storage capacity to contain all the information the department needed to store, and it was taking a long time for team members to access the data they needed. to fix the problem, the technician installed new, larger hard drives on all the computers.
Answers: 1
You know the right answer?
This question involves reasoning about arrays of integers. You will write methods in a class named A...
Questions
question
History, 18.10.2019 15:00
Questions on the website: 13722367