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
When the code that follows is executed, a message is displayed if the value the user entersvar userEntry = (prompt("Enter cost:"
Reika [66]

Answer:

The answer is "Option b".

Explanation:

In the given-code variable "userEntry" is defined that prompt the user to input value and in the next step, the conditional statement is used, which checks the input value is not a number and greater than 500 with use of OR operator. if the condition is true it uses the alert box to print the message, that's why in this question except "choice b" all were wrong.

4 0
3 years ago
Compare Fibonacci (recursion vs. bottom up)
ipn [44]

Answer:

C++ code explained below

Explanation:

#include<bits/stdc++.h>

#include <iostream>

using namespace std;

int FiboNR(int n)

{

int max=n+1;

int F[max];

F[0]=0;F[1]=1;

for(int i=2;i<=n;i++)

{

F[i]=F[i-1]+F[i-2];

}

return (F[n]);

}

int FiboR(int n)

{

if(n==0||n==1)

return n;

else

return (FiboR(n-1)+FiboR(n-2));

}

int main()

{

long long int i,f;

double t1,t2;

int n[]={1,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75};

cout<<"Fibonacci time analysis ( recursive vs. non-recursive "<<endl;

cout<<"Integer FiboR(seconds) FiboNR(seconds) Fibo-value"<<endl;

for(i=0;i<16;i++)

{

clock_t begin = clock();

f=FiboR(n[i]);

clock_t end = clock();

t1=double(end-begin); // elapsed time in milli secons

begin = clock();

f=FiboNR(n[i]);

end = clock();

t2=double(end-begin);

cout<<n[i]<<" "<<t1*1.0/CLOCKS_PER_SEC <<" "<<t2*1.0/CLOCKS_PER_SEC <<" "<<f<<endl; //elapsed time in seconds

}

return 0;

}

7 0
2 years ago
i have a bag of trail mix . one half of the bag is peanuts. 1/4 of the bag is chocolate candies , and 1/4 of the bag is died fru
Lelu [443]
In our bag, 1/2 is peanuts, 1/4 is chocolate and 1/4 is dried fruit.

The likelihood of drawing a chocolate therefore is 1/4. 

The likelihood of drawing a peanut is 1/2 and the likelihood of drawing a dried fruit is 1/4.

Thus, D is the correct answer because the 1/4 likelihood of drawing a chocolate is less than the 1/2 chance of drawing a peanut.
8 0
3 years ago
What is the disadvantage of a mesh topology?
-BARSIC- [3]

Answer:

Topology means arrangement of nodes

Explanation:

In computer science the word topology means the arrangement of nodes and elements in a network. For any topology we do need nodes and cables for maintaining the infrastructure.

In mesh topology the all nodes use to get connected by direct link. While each and every node is directly associated with  one another. In this infrastructure we do need lot cabling where every node will be connected with one another. While usage of good quality cable in network is  also expensive to manage. Although there are lot of benefits of this topology, where the transmission of data would never stop if node is not working the rest will be working to transfer the data among other nodes ,this is more secure because there is no traffic for data to travel via many nodes   to reach the destination. Every node is directly connected and communicate. So, once the node is not working the communication will not be stop but the maintenance and troubleshooting will be difficult in this infrastructure.

It is proved along with lot of benefits and network security ,this infrastructure is having some disadvantages as well. Cabling expense , maintenance cost etc  . usually small scale networks do not prefer mesh topology.  Small scale and low budget companies can  not afford this topology because it is expensive.

Although we do believe that the data security is most important for today's era ,so few companies those wanted to keep their information secure and confidential they must use mesh topology by ignoring the cost incurred for this set up. Data security and integrity would never be compromised by some of the companies.

Mesh topology is more safer, more quick infrastructure which is although very expensive , difficult to mange and maintain. Moreover it is overhead of cabling as well to connect every node but the demand of mesh topology would never be less. It is demanding and appealing topology still.

7 0
3 years ago
Read 2 more answers
An IT specialist is consulted about setting up a peer-to-peer network. What would the specialist say about security risk in this
ohaa [14]

I just did this, its A

6 0
3 years ago
Read 2 more answers
Other questions:
  • Test if a password entered is correct. The secret phrase is Ada Lovelace. Sample Run 1 Enter the Password: Ada Lovelace Sample O
    13·1 answer
  • How to do this? ICT Excel there's a screenshot attached
    6·1 answer
  • Henrietta, the owner of a very successful hotel chain in the Southeast, is exploring the possibility of expanding the chain into
    15·1 answer
  • You're an administrator for a large corporation and you are responsible for deploying computers often and quickly. What server d
    10·1 answer
  • Which of the following statement about CAD is NOT true A. It increase the productivity of designers B. It uses computer graphics
    8·1 answer
  • The first step to accurate coding is to identify the ___________ in the diagnostic statement.
    7·1 answer
  • PLEASE HELP AND FAST!!!!!<br>Which of the following devices uses binary code?
    6·2 answers
  • Given a sorted list of integers, output the middle integer. A negative number indicates the end of the input (the negative numbe
    12·1 answer
  • You do not have to move your fingers to click the top row reach keys.<br> 1. True <br> 2. False
    15·1 answer
  • Bob has started a company and registered its name with the government as a private corporation. He tries to create a domain name
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!