jueves, 9 de diciembre de 2010

suma de columnas verticalmente

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package matriz;
import java.io.*;
import java.util.*;

/**
*
* @author xxx
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException, IOException {

Scanner sn = new Scanner (new File ("in.txt"));
FileOutputStream fos = new FileOutputStream ("out.txt");
PrintStream ps = new PrintStream (fos);

int n = sn.nextInt();
int matriz [ ] [ ] = new int [n] [n];

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

matriz [i] [j] = sn.nextInt();

System.out.print(matriz [i] [j] + " " );
ps.print(matriz [i] [j] + " " );
}
System.out.println();
ps.println();

}

for(int i=0;i<=n-1;i++){
int suma = 0;
for (int j=0;j<=n-1;j++){
suma= suma + matriz [j] [i];

}
System.out.println( );
System.out.print(suma + " ");

ps.print(suma + " ");
}




// TODO code application logic here
//suma de columnas verticalmente
}
}

No hay comentarios:

Publicar un comentario