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
Write the definition of a method, isReverse, whose two parameters are arrays of ints of equal size. The method returns true if a
jok3333 [9.3K]

Answer:

The following are code in the Java Programming Language.

//define boolean type function

boolean isReverse(int ar[], int b[])

{

//declare integer type variable

int x;

//set the for loop

for (x=0; x < ar.length && ar[x] == b[ar.length-1-x];  x++);

return x == ar.length;

}

Explanation:

<u>The following are the description of the code</u>.

In the above code that is written in the Java Programming Language, we define the boolean data type function that is 'is Reverse()' and pass two array integer data type arguments that is 'ar', 'b' in the then, declare integer data type variable that is 'x'. Set the for loop that the boolean type value is true or false.

5 0
2 years ago
Consider the declaration of the struct houseType given in this chapter. Suppose firstHouse and secondHouse are variables of hous
Ilia_Sergeevich [38]

Answer:

See Explanation

Explanation:

The question is incomplete as there is no link pointing to the houseType struct of chapter 1.

So, I've answered the question from scratch

See attachment for explanation where I used comments to explain each line.

The program is as follows:

#include <iostream>

using namespace std;  

struct houseType{

   int firstHouse, secondHouse;

};

int main() {

   houseType hT;      

   cout << "Enter the price of both house: ";

   cin>> hT.firstHouse;

   cin>> hT.secondHouse;

   if(hT.firstHouse == hT.secondHouse){ cout<<"true";    }

   else{ cout<<"false";    }  

   return 0;

}

Download cpp
6 0
3 years ago
Why is script used for pre-production?
Grace [21]

Explanation:

Pre-production formally begins once a project has been greenlit. At this stage, finalizing preparations for production go into effect. Financing will generally be confirmed and many of the key elements such as principal cast members, director and cinematographer are set. By the end of pre-production, the screenplay is usually finalized and satisfactory to all the financiers and other stakeholders.

During pre-production, the script is broken down into individual scenes with storyboards and all the locations, props, cast members, costumes, special effects and visual effects are identified. An extremely detailed shooting schedule is produced and arrangements are made for the necessary elements to be available to the film-makers at the appropriate times. Sets are constructed, the crew is hired, financial arrangements are put in place and a start date for the beginning of principal photography is set. At some point in pre-production, there will be a read-through of the script which is usually attended by all cast members with speaking parts, the director, all heads of departments, financiers, producers, and publicists.

5 0
3 years ago
Read 2 more answers
Nathan wants to make the quotation stand out further. Which order of steps does he need to follow to do this task?
Alina [70]

Answer:

B.

Explanation:

Go to the Borders and Shading option, click the Shading tab, and click the color under the Fill option.

5 0
3 years ago
Read 2 more answers
Engineers perform a(n) blank to compare the possible negative effects of making a decision involving technology with the possibl
Bumek [7]

Answer: Experiment.

Explanation:

4 0
3 years ago
Read 2 more answers
Other questions:
  • A circuit contains two 500 OHM resistors connected in parallel and is supplied with 60 VDC. What is the current in the circuit?
    12·2 answers
  • What aspect of web design is Gloria following when she uses the same color scheme throughout a web page?
    12·1 answer
  • 3. The invention of the transistor was important to the development of computers because it
    5·1 answer
  • A device (or a software program on a computer) that can monitor data traveling on a network is known as a socket sniffer. ______
    15·1 answer
  • When it comes to collecting and organizing prospect and account​ information, salespeople have a large variety of computer syste
    15·1 answer
  • To add a new kind of information into the database you need to add a new table<br> true or false?
    7·2 answers
  • Which of the following helps create a positive community?
    11·1 answer
  • What department is cyber security
    6·2 answers
  • All _______ that store more than one piece of data ​
    12·1 answer
  • What's the difference between an operating system and an application software?​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!