/
Inicio :: Foros

 F.A.Q.F.A.Q.                  Conéctese para revisar sus mensajesConéctese para revisar sus mensajes   

PRODUCTO DE MATRICES.AYUDA

 
      Índice del Foro elrincondelc.com -> Java
Ver tema anterior :: Ver siguiente tema  
AutorMensaje
charly_rgn



Registrado: 25 Sep 2010
Mensajes: 2
Ubicación: lima - peru

MensajePublicado: 26/09/2010 11:39 am
Título: PRODUCTO DE MATRICES.AYUDA

SALU2: TRATO DE MULTIPLICAR 2 MATRICES ,PERO AL MOMENTO DE ARROJAR LOS RESULTADO NO VISUALIZA LAS MATRICES Y NI EL NUEVO MATRIZ...AHI LE DEJO EL CODIGO...ALGUNA IDEA GRACIAS,,,,

import java.io.*;

public class producto{
//Implementa métodos para llenar y multiplicar 2 matrices NxN (2x2)
//Rogers R.- 2003

private static float[][] M1; //Matriz 1
private static float[][] M2; //Matriz 2
private static float[][] R; //Matriz Resultante
private static int N = 2; //Orden de las Matrices

public static void main(String args[]) throws IOException{
M1 = new float[N][N];
M2 = new float[N][N];
R = new float[N][N];

System.out.print("Captura de Valores\n");
System.out.print("Valores para Matriz 1\n");
IngresaDatos(M1);
System.out.print("\nValores para Matriz 2\n");
IngresaDatos(M2);
System.out.println("Captura finalizada");
System.out.print("\nMatriz 1:\n");
Imprime(M1);
System.out.print("\nMatriz 2:\n");
Imprime(M2);
Multiplica();
System.out.print("\nMatriz Resultante:\n");
Imprime(R);
System.out.println();
}

//Metodo para cargar los datos en las matrices
public static void IngresaDatos(float m[][]) throws IOException{
String cad; //Para almacenar capura de teclado

//Define LeeBuf para capturar teclado
BufferedReader LeeBuf = new BufferedReader(new InputStreamReader(System.in));

//Llena Matriz
for(int i = 0; i < N; i++)
for(int j = 0; j < N; j++){
System.out.print("Ingrese valor [" + (i + 1) + "," + (j + 1) + "]: ");
cad = LeeBuf.readLine(); //Lee línea y la almacena en cad
m[j][i] = Float.parseFloat(cad); //Convierte cad a float y lo almacena en m[i, j]
} //Cierra for
} //Cierra IngresaDatos


//Método que calcula la Multiplicación de las dos matrices
public static void Multiplica()
{
float suma;
for(int i = 0; i < N; i++){ //Inicia ciclo filas
for(int j = 0; j < N; j++){ //Inicia ciclo columnas
suma = 0;
for(int k = 0; k < N; k++){ //Ciclo interno para las sumatorias
suma += M1[i][k] * M2[k][j];
}
R[i][j] = suma;
}
}
}

public static void Imprime(float m[][])
{
for(int i = 0; i < N; i++){
for(int j = 0; j < N; j++){
System.out.print(m[j] + " ");
}
System.out.print("\n");
}
}
}

MI PROBLEMA
================================0

Matriz 1:
[F@19821f [F@addbf1
[F@19821f [F@addbf1

Matriz 2:
[F@42e816 [F@9304b1
[F@42e816 [F@9304b1

Matriz Resultante:
[F@190d11 [F@a90653
[F@190d11 [F@a90653
Volver arriba
polly



Registrado: 19 Jul 2007
Mensajes: 618

MensajePublicado: 26/09/2010 1:58 pm
Título:

En el metodo Imprime() haces :
Código:

System.out.print(m[j] + " ");


y deberia ser:
Código:

System.out.print(m[i][j] + " ");


ya que 'm' es una matriz.

S2
_________________
enrmarc
Volver arriba
      Índice del Foro elrincondelc.com -> Java
Página 1 de 1Todas las horas están en GMT - 8 Horas

 
No puede crear mensajes
No puede responder temas
No puede editar sus mensajes
No puede borrar sus mensajes
No puede votar en encuestas

(c) ElRincondelC.com

Un proyecto de UrlanHeat.com