Create a class OperateArray in which you create a 2 x 3 integer array with all zeros in it. Allow the user to traverse the array to enter the 6 values in the array. The user will fill in the top row first, then the bottom row. The class should then subtract the bottom number from the top number in each column, and then add the results of the 3 subtractions to get a total. Enter the data shown below
| 6 5 4| Top row of array
|3 2 3| Bottom row of array
The correct answer is 7.

Respuesta :

Answer:

The programming language is not stated; however, I'll answer this question using Java programming language.

Because of the length of the program, comments are used to explain some lines

See Attachment for program file

Program starts here

import java.util.*;

public class OperateArray{

public static void main(String [] args)

{

 Scanner input = new Scanner(System.in);

 //Declare Array

 int arr[][] = new int[2][3];

 //Fill array with 0

 for(int row =0;row<2;row++)

 {

  for(int col=0;col<3;col++)

  {

   arr[row][col] = 0;

  }

 }

 //Prompt user for input

 for(int row =0;row<2;row++)

 {

  if(row == 0)

  {

   System.out.print("Enter top rows\n"); //Top rows

  }

  else

  {

   System.out.print("Enter bottom rows\n"); //Bottom Rows

  }

  for(int col=0;col<3;col++)

  {

   arr[row][col] = input.nextInt();

  }

 }

 //Initialize difference to 0

 int diff = 0;

 //Print and Calculate Difference

 for(int row =0;row<2;row++)

 {

  for(int col=0;col<3;col++)

  {

   if(row<1)

   {

   if(col<2)

   {

    System.out.print(arr[row][col]+" ");

   }

   else

   {

    System.out.print(arr[row][col]+" |Top Row of Array\n");

   }

   //Add top rows

   diff+=arr[row][col];

   }

   else

   {

    if(col<2)

   {

    System.out.print(arr[row][col]+" ");

   }

   else

   {

    System.out.print(arr[row][col]+" |Bottom Row of Array\n");

   }

   //Subtract bottom rows from top

   diff-=arr[row][col];

   }

  }

 }

 //Print Difference

 System.out.print("Difference: "+diff);

}

}

//End of Program

Ver imagen MrRoyal
It is the top row so it is 7