Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 5

import java.util.

Scanner;
class TransposeAMatrix
{
public static void main(String args[])
{
int m, n, c, d;

Scanner in = new Scanner(System.in);


System.out.println("Enter the number of rows and columns of matrix");
m = in.nextInt();
n = in.nextInt();

int matrix[][] = new int[m][n];

System.out.println("Enter elements of the matrix");

for (c = 0; c < m; c++)


for (d = 0; d < n; d++)
matrix[c][d] = in.nextInt();

int transpose[][] = new int[n][m];

for (c = 0; c < m; c++)


for (d = 0; d < n; d++)
transpose[d][c] = matrix[c][d];

System.out.println("Transpose of the matrix:");

for (c = 0; c < n; c++)


{
for (d = 0; d < m; d++)
System.out.print(transpose[c][d]+"\t");

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

import java.util.Scanner;

/*
* Java Program to transpose a Matrix. When you transpose
* a matrix rows are replaced by columns. For example,
* The transpose of a matrix is a new matrix whose rows are the columns of the
original.
*/
public class MatrixTransposeDemo {

public static void main(String[] args) {

System.out.println("Welcome to Java program to transpose a Matrix");


Scanner scnr = new Scanner(System.in);

System.out.println("Please enter details of matrix");


System.out.print("Please Enter number of rows: ");
int row1 = scnr.nextInt();
System.out.print("Please Enter number of columns: ");
int column1 = scnr.nextInt();
System.out.println();
System.out.println("Enter first matrix elements");
Matrix first = new Matrix(row1, column1);
first.read(scnr);

System.out.println("original matrix: ");


first.print();

// let's transpose the matrix now


first.transpose();

System.out.println("transpose of the matrix is ");


first.print();
scnr.close();

/*
* Java class to represent a Matrix. It uses a two dimensional array to
* represent a Matrix.
*/
class Matrix {
private int rows;
private int columns;
private int[][] data;

public Matrix(int row, int column) {


this.rows = row;
this.columns = column;
data = new int[rows][columns];
}

public Matrix(int[][] data) {


this.data = data;
this.rows = data.length;
this.columns = data[0].length;
}

public int getRows() {


return rows;
}

public int getColumns() {


return columns;
}

/**
* fills matrix from data entered by user in console
*
* @param rows
* @param columns
*/
public void read(Scanner s) {
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
data[i][j] = s.nextInt();
}
}
}

/**
* This method will transpose this matrix
*
* @return
*/
public void transpose() {
int[][] temp = new int[columns][rows];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
temp[j][i] = data[i][j];
}
}
data = temp;
}

/**
*
* @param matrix
*/
public void print() {
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
System.out.print(data[i][j] + " ");
}
System.out.println();
}
}

Cordial Saludo,

Nos complace informarle que usted ha sido seleccionado para iniciar la


fase del proceso de selección que adelanta nuestra compañía y del cual usted ha
manifestado interés en participar.

Para continuar con la siguiente fase se requiere que usted desarrolle


la siguiente prueba técnica:

Escriba una función que tome dos argumentos numéricos (N y M) mayores


que 2 y cree una matriz de tamaño N x M que contiene números aleatorios únicos
desde 1 hasta NxM y retorne cuántas columnas cumplen con la siguiente propiedad:

La suma de los elementos de la columna (total_columna) está por encima del promedio
de los totales de todas las
columnas pares.

Ejemplo para ( n = 3 y m =3)


c0|c1|c2

[5, 3, 8]

[1, 2, 4]

[9, 7, 6]

======

[15,12,18]

=======

Promedio columnas impares = 16.5

Cantidad de columnas cuyo total es mayor que 12 = 1

Resuelva la prueba usando un solo archivo (.java, .js , etc ), use el


siguiente formato para darle nombre al archivo de resolución:

{NUMERO_CEDULA}_{NOMBRES}_{FECHA_DE_DILIGENCIAMIENTO}.{Extension}

Ejemplos:

1010421945_JUAN-PABLO-PEREZ_2018-03-50-14-50.java

1010421945_JUAN-PABLO-PEREZ_2018-03-50-14-50.ts

1010421945_JUAN-PABLO-PEREZ_2018-03-50-14-50.js

1010421945_JUAN-PABLO-PEREZ_2018-03-50-14-50.py

1010421945_JUAN-PABLO-PEREZ_2018-03-50-14-50.php

Instrucción 1: Incluya un link al archivo de resolución de la prueba en


el formulario que recibira a continuación, este archivo debe subirse a google
drive o microsoft one drive o github (Ver campo #XX),
Instrucción 2: Adicione en el siguiente formulario el link de su respuesta,
en el campo que le sea requerido.

You might also like