Em Java also can use dimensional arrays (vectors) also can make use of two-dimensional arrays (matrices). How to create and declare the two-dimensional arrays is similar to the creation and reporting dimensional arrays.
The syntax for declaring the two-dimensional arrays is as follows:
nombre_arreglo data_type [] [] = new data_type [ rows] [columns ] / / 1st way
data_type [] [] = new name under data_type [ rows] [columns ] / / 2nd way
where data_type corresponds one of the primitive data types in Java (boolean, int, shot, long, byte, char, float or double) or objects (String, Object or defined).
nombre_arreglo is a valid ID for Java with which we use the two-dimensional array.
As for the one-dimensional arrangements to go a Java-dimensional array indices always start at 0. In addition, we use the length attribute to determine the number of rows and columns of a matrix.
matrix multiplication.
A practical example of operations with matrices (two dimensional arrays in Java) is to perform the multiplication of the elements of a matrix by another matrix elements. The following link is a video exemplifies the process for performing matrix multiplications.
The following code in the Java language performs multiplication of two matrices. NOTE: One of the rules for multiplication of matrices is that the number of columns in the first matrix must equal the number of rows in the second, as explained in the video. Therefore, the rows and columns indicate different matrices, multiplication is not performed.
Multiplicacion.java
Finally, I add a program, filling a matrix of n by m integers with random values \u200b\u200band then inverting the matrix content and presents it on screen. The method of reversing the content is to take a line or row of the matrix and reverse its contents, then move to the next line and perform the same procedure. And so on until the n rows of the matrix. Later the same process applies now to the columns.
Matrices.java
Multiplicacion.java
Finally, I add a program, filling a matrix of n by m integers with random values \u200b\u200band then inverting the matrix content and presents it on screen. The method of reversing the content is to take a line or row of the matrix and reverse its contents, then move to the next line and perform the same procedure. And so on until the n rows of the matrix. Later the same process applies now to the columns.
Matrices.java
0 comments:
Post a Comment