Computer Science, asked by ryanmha13, 10 months ago

Consider the following method:

public static void twoDimensions(int[][] numbers){
for (int i = 0; i < numbers.length - 1; i++){
for (int j = 0; j < numbers[i].length - 1; j++){
if (numbers[i][j] < numbers[i][j + 1]){
numbers[i][j] = numbers[i][j] + numbers[i + 1][j];
numbers[i + 1][j] = numbers[i + 1][j] / 2;
}
}
}
}


What are the contents of the following two-dimensional array after it is passed the following parameter?
{{44, 45, 16, 50},
{16, 12, 66, 9},
{52, 83, 3, 37},
{56, 61, 69, 61}}



{{44, 57, 16, 50},
{68, 6, 69, 9},
{26, 144, 1, 37},
{56, 30, 69, 61}}

A (

{{44, 45, 16, 50},
{16, 12, 66, 9},
{52, 83, 3, 37},
{56, 61, 69, 61}}

B (

{{89, 22, 66, 25},
{16, 78, 33, 9},
{135, 41, 40, 18},
{56, 61, 69, 61}}

C (
{{52, 45, 49, 50},
{34, 53, 33, 9},
{54, 41, 37, 37},
{28, 61, 34, 61}}

D (

{{60, 45, 82, 50},
{60, 95, 33, 9},
{82, 41, 72, 37},
{28, 61, 34, 61}}

A , B , C or D ?
unanswered

Answers

Answered by Kmakashahkma
0

Answer: D

Syntax:

package com.company;

public class TryandError {

   public static void twoDimensions(int[] numbers){

       for (int i : numbers) {

           System.out.print(i);

           System.out.print("\t");

       }

       System.out.println();

   }

   public static void main(String[] args) {

       int numbers1[][] = {{44, 45, 16, 50},

                                       {16, 12, 66, 9},

                                       {52, 83, 3, 37},

                                       {56, 61, 69, 61}};

       for (int i = 0; i < numbers1.length - 1; i++){

           for (int j = 0; j < numbers1[i].length - 1; j++){

               if (numbers1[i][j] < numbers1[i][j + 1]){

                   numbers1[i][j] = numbers1[i][j] + numbers1[i + 1][j];

                   numbers1[i + 1][j] = numbers1[i + 1][j] / 2;

               }

           }

       }

       for (int[] numbers : numbers1) {

           twoDimensions(numbers);

       }

   }

}

Output:

60 45 82 50  

60 95 33 9  

82 41 72 37  

28 61 34 61

You can try to run the syntax on any java software such as IntelliJ IDEA, Netbeans IDE, etc.

Hopefully, my answer could solve your question and help you to understand better.

Similar questions