Question
this is the code which I have for the assignment. Programming requirements: 1. Use only one return statement in each method. 2. Write comments that
this is the code which I have for the assignment.
Programming requirements:
1. Use only one return statement in each method. 2. Write comments that includes your name and a short description of each method. 3. Remove any comments generated by the IDE. 4. Format your code. I recommend using the IDEs formatting tool. 5. Do not a loops to copy the elements of one array to another array. Instead, use the System.arraycopy method.
public class Homework1 {
public static void rotateArray(int[] arr, int rotate) {
//public static void display(int[] arr){
for (int x: arr){
System.out.print(x + " ");}System.out.println();}
public static void main(String[] args){
int[][] numbers= { {7, 6, 5, 3, 2, 1}, {109}, {-77, 61, 2}};
int[] output = twoDimensionalToOneDimensional(numbers);
if (output == null){
System.out.println("The 1-D array is null");
}
else
{
display(output);}
System.out.println();
numbers = null;
output = twoDimensionalToOneDimensional(numbers);
if (output == null){
System.out.println("The 1-D array is null");
}
else{display(output);
}
System.out.println();
int[] x = {3, 4, 8, -1, 2, 4};
display(x);
rotateArray(x, 2);
display(x);
System.out.println();}
//private static void rotateArray(int[] x, int i) {
// TODO Auto-generated method stub
private static void display(int[] output) {
// TODO Auto-generated method stub
}
private static int[] twoDimensionalToOneDimensional(int[][] numbers) {
// TODO Auto-generated method stub
return null;
B Asigient bue by Sept 1, 2017, 11:59 pm Write methods with the following headers 1. public static int[] twoDimensionalToOneDimensional(intU00 arr) . if arr is null then return nul otherwise (i) copy the rows of arr to a one-dimensional array and (i) return the one-dimensional array. the length of the returned array should be equal to the number of values stored in arr copy the rows in ascending order. In other words, first copy row 0 to the one- dimensional array, then row 1, 2, etc. . Example Assume int[][] arr = {(1, 20, 50), {5, 8)(22, 100, 200, 1}); Also assume we have the local variable int[] returnArray After copying the contents of arr to returnArray this array contains the following values: (1, 20, 50, 5, 8, 22, 100, 200, 1); Suggestion: Each row of arr may have a different number of columns. If arr isn't null, then (a) write a loop that finds the sum of row lengths and (b) declare an int[] array whose length is equal to the number calculated in step a
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started