Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/12/2010, 12:38
JssEmilio
 
Fecha de Ingreso: septiembre-2010
Mensajes: 9
Antigüedad: 13 años, 7 meses
Puntos: 0
AYUDA: ¿Como sumar los elementos de la primera y ultima columna en una matriz?

Me dejaron de tarea hacer este programa, pero ya nosé como hacerle, como sumar los elementos de la primera y ultima columna....

Ejercicio...
6. Escriba un algoritmo para que lea una matriz de orden 5 x 3, después sume todos los elementos de la primera y última columna, al final imprimir la matriz y la suma.

Esto es lo que llevo...

import java.io.*;
class Matriz_6 {
public static void main (String[] args) throws java.io.IOException {

//Declaraciones
String lectura;
int m=0, n=0;

DataInputStream recibe = new DataInputStream(System.in);

System.out.println ("Programa 6 matrices");
System.out.println ("--------------------");

do{
System.out.print ("Ingrese valor de filas: ");
try{
lectura=recibe.readLine();
m=Integer.parseInt(lectura);
break;
}catch(NumberFormatException e){
System.out.println ("ERROR dato no aceptado.");
continue;
}

}while(true);

do{
System.out.print ("Ingrese valor de columnas: ");
try{
lectura=recibe.readLine();
n=Integer.parseInt(lectura);
if(n!=m){
System.out.println ("ERROR tienen que ser iguales.");
continue;
}
break;
}catch(NumberFormatException e){
System.out.println ("ERROR dato no aceptado.");
continue;
}

}while(true);

System.out.println (" Mensaje: la medida de las matices es la misma.");

int matriz_1[][]= new int[m][n];
int matriz_2[][]=new int[m][n];
int matriz_suma[][]=new int[m][n]; // matriz para guardar la suma.

// matriz uno
//__________________________________________________ ____________

System.out.println ( "matriz uno:" );
System.out.println ("--------------------------------");

for(int i=0; i<m; i++){
for(int j=0; j<n; j++){
do{
System.out.print ("Ingrese su valor: ");
lectura=recibe.readLine();
try{
matriz_1[i][j]=Integer.parseInt(lectura);
break;
}catch(NumberFormatException e){
System.out.println ("ERROR dato no aceptado tiene que ser numero.");
continue;
}

}while(true);

}
}

// matriz dos
//__________________________________________________ __

System.out.println ( "matriz dos:" );
System.out.println ("------------------------------------");

for (int i = 0; i<m; i++){
for(int j=0; j<n; j++){

do{
System.out.print ("Ingrese su valor: ");
try{
lectura=recibe.readLine();
matriz_2[i][j]=Integer.parseInt(lectura);
break;
}catch(NumberFormatException e){
System.out.println ("ERROR dato no aceptado tiene que ser numero.");
continue;
}

}while(true);

}
}








}
}