1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
lianna [129]
3 years ago
11

Write a method transpose, that takes as argument a 2D array of integers, myTable, and returns the transpose of myTable. The tran

spose is a 2D array where rows from the original array become columns. In the first example below, the first row (2,3,4) became the first column 2, 4 and the second row (5,6,4) became the second column 4 Do not print anything in the transpose method Example: Input 1 Answer 2 1 4 7 2 5 8 3 6 9 1 Input 2 1 2 3 4 5 6 7 8 9 Answer
Computers and Technology
1 answer:
Gelneren [198K]3 years ago
5 0

Answer:

The program to this question can be given as:

Program:

import java.util.*; //import package

public class Main //defining class

{

public static int[][] transpose(int[][] a1) //defining function transpose

{

int i,j; //define variables

int[][] transpose = new int[a1[0].length][a1.length]; //define variable transpose.

//loop for transpose matrix.

for(i = 0; i < a1.length; i++)  

{

for(j = 0; j < a1[i].length; j++)

{

transpose [j][i] = a1[i][j]; //hold value in transpose variable

}

}

return transpose ; //return transpose matrix.  

}

public static void main(String[] args) //main method.

{

int row,col,i,j; //defining variable.

Scanner obj = new Scanner(System.in); //creating Scanner class Object

System.out.print("Enter number of rows: ");//message

row = obj.nextInt(); //input rows form user.

System.out.print("Enter number of columns: ");//message

col = obj.nextInt(); //input columns form user.

int[][] a1 = new int[row][col]; //defining array.

System.out.println("Enter matrix"); //message

// loop for input array elements from user

for(i=0; i<a1.length;i++)  

{

for(j=0; j<a1[i].length;j++)  

{

a1[i][j]=obj.nextInt(); //input in array variable.

}

}

System.out.println("Matrix you insert :"); //message

// loop for display array.

for(i=0; i<a1.length;i++)  

{

for(j=0; j<a1[i].length;j++)  

{

System.out.print(a1[i][j]+" "); //print matrix

}

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

}

int[][] result = transpose(a1); //define result array variable that holds function value.

System.out.println("Transposed matrix is :");

//use loop for print Transpose matrix.

for(i = 0;i < result.length;i++)

{

for (j = 0; j < result[i].length;j++)

{

System.out.print(result[i][j] + " "); //print matrix

}

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

}

}

}

Output:

Enter number of rows: 2

Enter number of columns: 3

Enter matrix

2

3

4

9

8

7

Matrix you insert :

2 3 4  

9 8 7  

Transposed matrix is :

2 9  

3 8  

4 7  

Explanation:

The description of the above program can be given as:

  • In the above program firstly import a package, then declare a class that is "Main" inside a class defining a transpose() function this function returns a matrix in transpose form.
  • In the main class, we define a variable and matrix that is "row, col, i, j and a1[][]".  Then we Creating a scanner class object, which is used by row, col and a1[][] variables for user input.  
  • The row and col variables are used to declare matrix size and i, j variable is used in the loop for insert and display matrix.  
  • a1[][] matrix is used for input matrix elements and passes into transpose() function as an argument that returns a value that is held in the result variable. This is used as a loop for the print transpose matrix.

You might be interested in
TRUE OR FALSE!!! <br> Your location can be tracked via your digital footprint.
laiz [17]
Sadly this statement is true
3 0
3 years ago
someone help me my browser is updated I don't know what to do someone help me please I'm trying to watch Crunchyroll.​
levacccp [35]

Answer: use chrome or firefox the browser app your using is one that they dont support

Explanation:

4 0
3 years ago
Read 2 more answers
PLEASE HURRY PLEASE HELP THIS CLASS ENDS TODAY AND I NEED HELP
Fofino [41]

Answer:

She could have given access to the computer to the techician

Explanation:

"as well as any special settings or configurations she thinks may be relevant." This might inculd any information to hack the computer

6 0
3 years ago
Read the following scenarios carefully and select a suitable storage device for each situation. Make sure to justify your choice
labwork [276]

Answer:

SSD drive or sd card

Explanation:

Optical wouldn't have enough data and could get easily damaged by the movement of the armed forces.Hard Drives would be insanely bad as if you even slightly moved while it were moving you would corrupt data. SSD doesn't get damaged as easily as these two and can hold a sufficient amount of data for its size.

8 0
3 years ago
The large capacity, high-definition optical discs designed to store hi-def video and video games are _______,
snow_tiger [21]
The large capacity, high-definition optical discs designed to store hi-def video and video games are  called Blu-ray.  These discs have a capacity of 50 gigabytes on one side. Blu-ray also features data streams at 36 megabits per second (Mbps<span>), fast enough for high quality video recording.</span>
4 0
3 years ago
Other questions:
  • Samantha was calculating a mathematical formula on an electronic spreadsheet. She used multiple values to recalculate the formul
    12·2 answers
  • ____ deals with ensuring that data is protected against unauthorized access, and if the data are accessed by an authorized user,
    10·1 answer
  • If you have a mix of 32-bit and 64-bit versions of windows, which architectures should you add a unattended installation file fo
    7·1 answer
  • Which of the following cannot be performed from the windows task manager?
    15·2 answers
  • Which of the following terms are aspect ratios for devices? 'select all that apply
    11·1 answer
  • Another html/css assignment, drop css code below, thank you
    15·1 answer
  • 2.27 LAB: Driving costs Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both doubles) as
    14·2 answers
  • :)
    5·1 answer
  • Types of Computer games​
    6·1 answer
  • Hi. I'm a beginner in python. Can anyone tell me what I'm missing or doing wrong, because I can't figure out why my messages in
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!