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 11:50
You have written, as part of a school assignment, a research paper on the solar system. you want to share this paper on your school website. on which type of server will you upload it?
Answers: 1
question
Computers and Technology, 22.06.2019 18:30
Which of these options are the correct sequence of actions for content to be copied and pasted? select content, click the copy button, click the paste button, and move the insertion point to where the content needs to be inserted. click the copy button, select the content, move the insertion point to where the content needs to be inserted, and click the paste button. select the content, click the copy button, move the insertion point to where the content needs to be inserted, and click the paste button. select the content, move the insertion point to where the content needs to be inserted, click the copy button, and click the paste button.
Answers: 3
question
Computers and Technology, 23.06.2019 10:30
How would you categorize the software that runs on mobile devices? break down these apps into at least three basic categories and give an example of each.
Answers: 1
question
Computers and Technology, 23.06.2019 18:30
Janice recently received her college degree and is looking for a job. she is worried that since she just finished school, she will be required to repay her perkins and direct subsidized loans immediately. janice pulls out the paperwork she signed and reviews it again for repayment information. after reading all of the information, janice discovers that
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, 20.11.2020 07:40
question
Mathematics, 20.11.2020 07:40
question
History, 20.11.2020 07:40
question
Health, 20.11.2020 07:40
question
Business, 20.11.2020 07:40
Questions on the website: 13722363