import java.util.Scanner;
public class algoritmo_10_matriz {
Scanner leer= new Scanner (System.in);
public static void main(String[] args){
algoritmo_10_matriz menu= new algoritmo_10_matriz();
menu.menuGeneral();
}
public int menuGeneral(){
int opcion;
do{
System.out.println("");
System.out.println("===================================================");
System.out.println("================= MENU DE OPCIONES ================");
System.out.println("===== 1.SUMA DE MATRICES ====");
System.out.println("===== 2.MULTIPLICACION DE MATRICES ====");
System.out.println("===== 3.TRANSPUESTA MATRIZ A^B ====");
System.out.println("===== 4.SUMA DIAGONAL PRINCIPAL MATRIZ A^B ====");
System.out.println("===== 5.MAXIMO Y MINIMO MATRIZ A ^ B ====");
System.out.println("===== 6.COLUMNA IMPAR ^ FILAS PARES MATRIZ A^B ====");
System.out.println("===== 7.SALIR ====");
System.out.println("===================================================");
System.out.print("Ingrese una opcion: ");
opcion=leer.nextInt();
switch(opcion){
case 1: SumadeMatriz(); break;
case 2: MultiplicacionMatriz();break;
case 3: TranspuestaMatriz();break;
case 4: DiagonalPrincipalMatrices();break;
case 5: MaximoMinimoMatriz();break;
case 6: ColumnaImparFilaPar();break;
case 7: System.out.println("................Saliendo del menu ..............");
System.exit(0); break;
default: System.out.println("Ingrese una opcion valida.......!!"); break;
}
}while(opcion != 8);
return 0;
}
public void ColumnaImparFilaPar(){
int n, m, i, j;
int A[][] = new int[10][10];
int B[][] = new int[10][10];
System.out.print("Ingrese dimension n: ");
n = leer.nextInt();
System.out.print("Ingrese dimension m: ");
m = leer.nextInt();
System.out.println("INGRESE VALORES MATRIZ A");
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
System.out.print("A[" + (i) + "," + (j) + "]= ");
A[i][j] = leer.nextInt();
}
}
System.out.println("INGRESE VALORES MATRIZ B");
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
System.out.print("B[" + (i) + "," + (j) + "]= ");
B[i][j] = leer.nextInt();
}
}
//IMPRIMIENDO MATRICES A Y B
System.out.println("======== MATRIZ A =========");
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
System.out.print("\t" + A[i][j]);
}
System.out.println();
}
System.out.println("====== MATRIZ B ========");
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
System.out.print("\t" + B[i][j]);
}
System.out.println();
}
System.out.println(" MATRIZ A --->>> (COLUMNAS IMPARES ^ FILAS PARES)");
//columnas impares
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
if(j%2==1){
System.out.print("\t"+A[i][j]);
}
}
}
//filas pares
System.out.println("");
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
if(i%2==0){
System.out.print("\t"+A[i][j]);
}
}
}
System.out.println("");
System.out.println(" MATRIZ B --->>> (COLUMNAS IMPARES ^ FILAS PARES)");
//columnas impares
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
if(j%2==1){
System.out.print("\t"+B[i][j]);
}
}
}
//filas pares
System.out.println("");
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
if(i%2==0){
System.out.print("\t"+B[i][j]);
}
}
}
Home »
» Mostrar Valores de la columna impar y filas pares de dos matrices en java
0 comments:
Publicar un comentario