Question

Consider the following definitions int[ ][ ] numbers = {{1, 2, 3},                                &

Consider the following definitions

int[ ][ ] numbers = {{1, 2, 3},

                                {4, 5, 6} };

The following code below produces

for (int row = numbers.length - 1; row >= 0; row -- )

{

for (int col = 0; col < numbers[0].length; col ++)

{

System.out.print (numbers [row][col]);

}

}

Homework Answers

Answer #1

The code produces the following output:

456123

Explanation:

//Here is a 2D array with 2 rows and 3 columns

int[ ][ ] numbers = {{1, 2, 3}, {4, 5, 6} };

//the for loop below starts from values row= 2-1 = 1

// so the loop runs from 1 to 0

for (int row = numbers.length - 1; row >= 0; row -- )

{

// this loop is for each columns runs from 0 to less than 3

// here we are accessing 0th, 1st and 2nd columns of each row

for (int col = 0; col < numbers[0].length; col ++)

{

// printing the current index value of 2d matrix numbers

System.out.print(numbers [row][col]);

}

}

so , if you see we counting rows 1 to 0

and columns from 0 to 2

1st row 0th,1st and 2nd column values gets printed followed by 0th row 1st and 2nd column values gets printed.

456123

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Consider the following definitions int[ ][ ] numbers = {{1, 2, 3},                                &
Consider the following definitions int[ ][ ] numbers = {{1, 2, 3},                                 {4, 5, 6} }; The following code below produces for (int row = numbers.length - 1; row >= 0; row -- ) { for (int col = 0; col < numbers[0].length; col ++) { System.out.print (numbers [row][col]); } }
Consider the following two methods: public static boolean isTrue(int n){        if(n%2 == 0)          ...
Consider the following two methods: public static boolean isTrue(int n){        if(n%2 == 0)           return true;        else           return false; } public static int Method(int[] numbers, int startIndex) { if(startIndex >= numbers.length)        return 0; if (isTrue(numbers[startIndex]))      return 1 + Method(numbers, startIndex + 1); else      return Method(numbers, startIndex + 1); } What is the final return value of Method() if it is called with the following parameters: numbers = {1, 2, 2, 3, 3,...
public static void main(String[] args) { //Given the following code : int[][] array2D = {{3, 4,...
public static void main(String[] args) { //Given the following code : int[][] array2D = {{3, 4, 5, 1}, {3,6,1,2}, {1,3,6,5}; Answer : 1- All values ​​of array2D are automatically 0 ? Yes or No 2- What is the value of array2D [3] .length ?________ 3-  The value that array2D.length shows is 12: Yes or No ? 4- Assign the value of 12 to the element in the third row, fourth column : 5- the value obtained when calculating array2D [1] [1]...
Java question Consider the following: 1 class SnoopDogg { 2 int count; 3 } 4 class...
Java question Consider the following: 1 class SnoopDogg { 2 int count; 3 } 4 class Test { 5 public static void main ( String [] args ) { 6 SnoopDogg myCount = new SnoopDogg (); 7 myCount.count = 0; 8 int times = 0; 9 increment( myCount, times ); 10 System.out.println( myCount.count ); 11 System.out.println( times ); 12 } 13 public static void increment (SnoopDogg sd, int times ) { 14 sd.count = sd.count + 1; 15 times =...
I NEED THIS ANSWER FOR MY DATA STRUTURE CLASS: Consider the following two methods: public static...
I NEED THIS ANSWER FOR MY DATA STRUTURE CLASS: Consider the following two methods: public static boolean isTrue(int n){        if(n%2 == 0)           return true;        else           return false; } public static int Method(int[] numbers, int startIndex) { if(startIndex >= numbers.length)        return 0; if (isTrue(numbers[startIndex]))      return 1 + Method(numbers, startIndex + 1); else      return Method(numbers, startIndex + 1); } What is the final return value of Method() if it is called with the...
[ 1 3 9 -7 0 1 4 -3 2 1 -2 1] find basis for...
[ 1 3 9 -7 0 1 4 -3 2 1 -2 1] find basis for col A. dimension of col A find basis for nul A. dimension of nul A find basis for row A. dimension of row A asap plz, tyouuu
def count_evens(values: List[List[int]]) -> List[int]: """Return a list of counts of even numbers in each of...
def count_evens(values: List[List[int]]) -> List[int]: """Return a list of counts of even numbers in each of the inner lists of values.    >>> count_evens([[10, 20, 30]]) [3] >>> count_evens([[1, 2], [3], [4, 5, 6]]) [1, 0, 2] """   
What is the output of the following code segment? public class Exception { ... static int...
What is the output of the following code segment? public class Exception { ... static int divider(int x, int y) { try { return x/y; } catch (ArrayIndexOutOfBoundsException a) { System.out.print("A"); return 1; } } static int computer(int x, int y) { try { return divider(x,y); } catch (NullPointerException b) { System.out.print("B"); } return 2; } public static void main(String args[]){ try { int i = computer (100, 0); } catch (ArithmeticException c) { System.out.print("C"); } } } ABC A...
In Java programming language 11.Create the code for a for loop to print the numbers 1  through...
In Java programming language 11.Create the code for a for loop to print the numbers 1  through 5 inclusive vertically so the output is 1 2 3 4 5 11b What is the output of the following               OUTPUT int i=3; while(int i >0) { System.out.println(i); i--; } 11c What is the output of the following               OUTPUT for(int i=3;i<10;i++) System.out.println(3*i); 11d Create the line of code to print the numbers 10 through 1 decreasing by 1 each time 11e Create the line of code...
let us create a variable for a row vector a = [1, 4, 1, 3, 2,...
let us create a variable for a row vector a = [1, 4, 1, 3, 2, 5, 0] and calculate the mean value of its elements using the Matlab function ‘mean’ and store this value in variable aMean. Fig. 1 gives the Matlab code to do this. a = [1, 4, 1, 3, 2, 5, 0]; aMean = mean(a); Figure 1: Matlab code – row vector and mean of its elements. Let us now construct a row vector b that...