This document contains the code for a Java program that performs operations (addition, subtraction, multiplication) on matrices. It defines a class called Matriz with a main method that uses a Scanner to get user input. The main method displays a menu to select an operation, and uses nested for loops and arrays to store and manipulate 3x3 matrices based on the selected operation. The results are printed to the console.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
134 views7 pages
MHLC U4 Ea Sise
This document contains the code for a Java program that performs operations (addition, subtraction, multiplication) on matrices. It defines a class called Matriz with a main method that uses a Scanner to get user input. The main method displays a menu to select an operation, and uses nested for loops and arrays to store and manipulate 3x3 matrices based on the selected operation. The results are printed to the console.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7
LICENCIATURA EN MATEMATICAS
NOMBRE: SILVIA SANCHEZ ESPINOZA
MATRICULA: ES172015001 UNIDAD 4 ACTIVIDAD: EVIDENCIA DE APRENDIZAJE MATERIA: HERRAMIENTAS Y LENGUAJES COMPUTACIONALES DOCENTE: M.C ELENA TZETZANGAR AGUIRRE MEJIA package matriz; import java.util.*; import java.util.InputMismatchException; import java.util.Scanner; public class Matriz {
public static void main(String[] args){
Scanner pd = new Scanner(System.in); int op; do{ System.out.println("OPERACIONES CON MATRICES"); System.out.println("1)SUMA"); System.out.println("2)RESTA"); System.out.println("3)MULTIPLICACION"); System.out.println("4)SALIR"); System.out.print("teclee una opcion:"); op =pd.nextInt(); switch(op){ case 1: int matriza[][] = new int [3][3]; int matrizb[][] = new int [3][3]; int matrizc[][] = new int [3][3]; int i, j;
Scanner dato = new Scanner (System.in);
System.out.println("Datos de la Matriz A :");
for (i=0; i<=2; i++){ for (j=0; j<=2; j++){ System.out.print("Escribir valor " + i + " , " + j + " : "); matriza [i][j]= dato.nextInt(); } }
System.out.println("Datos de la Matriz B :");
for (i=0; i<=2; i++){
for (j=0; j<=2; j++){ System.out.print("Escribir valor " + i + " , " + j + " : "); matrizb [i][j]= dato.nextInt(); } }
for (i=0; i<=2; i++){
for (j=0; j<=2; j++){ matrizc [i][j]= matriza[i][j]+matrizb[i][j]; } }
System.out.println("Matriz resultante de la suma :");
for (i=0;i<=2;i++){ for (j=0;j<=2;j++) { System.out.print(matrizc[i][j] + " "); } System.out.println(""); } break; case 2: int matrizf[][] = new int [3][3]; int matrizd[][] = new int [3][3]; int matrize[][] = new int [3][3]; int a, b;
Scanner datos = new Scanner (System.in);
System.out.println("Datos de la Matriz A :");
for (a=0; a<=2; a++){
for (b=0; b<=2; b++){ System.out.print("Escribir valor " + a + " , " + b + " : "); matrizf [a][b]= datos.nextInt(); } }
System.out.println("Datos de la Matriz B :");
for (a=0; a<=2; a++){
for (b=0; b<=2; b++){ System.out.print("Escribir valor " + a + " , " + b + " : "); matrizd [a][b]= datos.nextInt(); } }
for (a=0; a<=2; a++){
for (b=0; b<=2; b++){ matrize [a][b]= matrizf[a][b]-matrizd[a][b]; } }
System.out.println("Matriz resultante de la suma :");
for (a=0;a<=2;a++){ for (b=0;b<=2;b++) { System.out.print(matrize[a][b] + " "); } System.out.println(""); } break; case 3: int matrizg[][] = new int [3][3]; int matrizh[][] = new int [3][3]; int matrizi[][] = new int [3][3]; int u,v;
Scanner datos1 = new Scanner (System.in);
System.out.println("Datos de la Matriz A :");
for (u=0; u<=2; u++){ for (v=0; v<=2; v++){ System.out.print("Escribir valor " + u + " , " + v + " : "); matrizg [u][v]= datos1.nextInt(); } }
System.out.println("Datos de la Matriz B :");
for (u=0; u<=2; u++){
for (v=0; v<=2; v++){ System.out.print("Escribir valor " + u + " , " + v + " : "); matrizh [u][v]= datos1.nextInt(); } }
for (u=0; u<=2; u++){
for (v=0; v<=2; v++){ matrizi [u][v]= matrizg[u][v]-matrizh[u][v]; } }
System.out.println("Matriz resultante de la suma :");
for (u=0;u<=2;u++){ for (v=0;v<=2;v++) { System.out.print(matrizh[u][v] + " "); } System.out.println(""); } break; case 4: System.out.println("¡HASTA LUEGO!"); break; }}while(op!=4); }}