import java.util.*;
import java.lang.*;
import java.io.*;
class Main {
public static void main(String[] args) {
Scanner tecl = new Scanner(System.in);
// Crear vector de texto y vector numérico
String [] vector = new String[5];
int [] otroArreglo = {125,150,175,200,225,250,275,300,325};
// Obtener y mostrar tamaño del vector
int tama = otroArreglo.length;
System.out.println("El tamaño del arreglo de una dimensión (Vector) es: " + tama);
for(int v=0; v < otroArreglo.length; v++){
System.out.println("\nEn la posición : " + v + " se encuentra el valor de: " + otroArreglo[v]);
if(v<vector.length){
vector[v] = tecl.nextLine();
}
}
// Declarar matriz y variables de tamaño
int [][] arreglo2D;
int f=0;
int c=0;
// Solicitar filas y columnas
System.out.println("Cuantas filas desea agregarle a su matriz: ");
f = tecl.nextInt();
System.out.println("Cuantas columnas desea agregarle a su matriz: ");
c = tecl.nextInt();
arreglo2D = new int[f][c];
// Generar números aleatorios
Random rock = new Random();
System.out.println("Valores f y c : " + f + " - " + c);
for(int i=0; i<f; i++){
for (int j=0; j<c; j++){
int x = rock.nextInt(99);
arreglo2D[i][j] = x;
}
}
System.out.println("\n Valor en la fila 3 columna 2: " + arreglo2D[2][1] );
System.out.println("\n\n" );
// Imprimir matriz completa
for(int i=0;i<f;i++){
for (int j=0; j<c;j++){
System.out.print(arreglo2D[i][j] + " - ");
}
System.out.println("\n");
}
//matriz L
// Primera columna y última fila
System.out.println("\n\nMatriz con forma de L:\n");
for(int i=0; i<f; i++){
for(int j=0; j<c; j++){
if(j == 0 || i == f - 1){
System.out.print("00 - ");
} else {
System.out.print(arreglo2D[i][j] + " - ");
}
}
System.out.println("\n");
}
// Matriz en forma de L invertida
// Última columna y última fila
System.out.println("\n\nMatriz con forma de L invertida:\n");
for(int i=0; i<f; i++){
for(int j=0; j<c; j++){
if(j == c - 1 || i == f - 1){
System.out.print("00 - ");
} else {
System.out.print(arreglo2D[i][j] + " - ");
}
}
System.out.println("\n");
}
// Matriz en forma de T
// Primera fila y columna central
System.out.println("\n\nMatriz con forma de T:\n");
for(int i=0; i<f; i++){
for(int j=0; j<c; j++){
if(i == 0 || j == c / 2){
System.out.print("00 - ");
} else {
System.out.print(arreglo2D[i][j] + " - ");
}
}
System.out.println("\n");
}
// J
System.out.println("\n\nMatriz con forma de J:\n");
for(int i=0; i<f; i++){
for(int j=0; j<c; j++){
if(j == c - 1 ||
(i == f - 1 && j > 0) ||
(j == 0 && i > f/2)){
System.out.print("00 - ");
} else {
System.out.print(arreglo2D[i][j] + " - ");
}
}
System.out.println("\n");
}
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: