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
Many professional photographers take pictures of people. What skills would someone have to have to be successful in these types
Galina-37 [17]
Wedding photographer
you are taking pictures of large groups of all kinds of people from 2 different sides of a family 

could you add me as best answer if this is correct?

7 0
3 years ago
বর্তমান করােনার ন্যায় পরিস্থিতি অর্থাৎ স্বাভাবিক শ্রেণি কার্যক্রম পরিচালনা সম্ভব
Zarrin [17]

Answer:

ayo fam

Explanation:

I dont think this is supposed to be here lol

5 0
3 years ago
Read 2 more answers
What language do the Vikings speak in the game " For Honor"?
aivan3 [116]
In the game the Vikings speak icelandic
3 0
2 years ago
Read 2 more answers
Implement a function named largerThanN that accepts three arguments: an array of type int, the size of the array of type int and
levacccp [35]

Answer:

import java.util.Scanner;

public class NewArray {

//Main Method begins here

   public static void main(String[] args) {

   int [] numbers = {30,20,50,2,-1,44,3,12,90,32}; //The given array

   Scanner in = new Scanner(System.in);

       System.out.println("enter a number");

       int n = in.nextInt(); //Receive the number from the user

       //Calling the method largerThanN

       largerThanN(numbers, numbers.length,n);

   }

//The method largerThanN begins here

   public static void largerThanN(int []intArray, int arraySize, int n){

       for(int i = 0; i < intArray.length; i++){

           if(intArray[i] > n){

               System.out.println(intArray[i]);

           }

       }

   }

}

Explanation:

Uisng the Java prograamming language the solution is provided above.

Please see the comments within the code for detailed explanation

The key logic within the method largerThanN () is using a for loop to iterate the entire array. Within the for loop use an if statement to compare each element with the the number n entered by the user

6 0
3 years ago
Setting financial priorities and goals will help you save money for future needs <br> True or false?
allsm [11]
Hey there!

Here is your answer:

<u><em>The proper answer to this question is option A "true".</em></u>

Reason:

<u><em>Financial priorities, and goals would help make a person more money. Goals would include: Opening bank accounts, adding money to some sort of fund, or putting money into a bank account.</em></u>

<em>Therefore the answer is option A!</em>

If you need anymore help feel free to ask me!

Hope this helps!

~Nonportrit 
3 0
3 years ago
Other questions:
  • Drag the correct type of update to its definition.
    5·1 answer
  • Send a document as a PDF when A. you want the recipient to make changes to the file. B. it needs to be printed. C. it contains m
    10·1 answer
  • The version of Windows that first provided networking capabilities was _____.
    12·2 answers
  • Eniac was the first desktop computer. t/f
    5·1 answer
  • Self contained sequences of actions to be performed are?
    6·1 answer
  • 1.Input device which transfers information and images from physical documents to computer files.
    14·1 answer
  • Which location-sharing service offers items for users as a gaming component and also allows them to collectively link their chec
    9·2 answers
  • What is work flexibility?
    15·1 answer
  • How are the number of rows calculated.​
    14·1 answer
  • What kind of skill is persuasion?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!