/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package matriz2;
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")); //crea archivo //escaner crea y lee
FileOutputStream fos= new FileOutputStream ("out.txt"); //crea y envia un archivo de salida
PrintStream ps = new PrintStream (fos); // imprime lo q se tiene en fos fos= out.txt
int comida = sn.nextInt(); // lee primer valor
int salsa [] [] = new int [comida] [comida]; //crea una matriz
for (int i=0;i<=comida-1;i++){
for (int j=0;j<=comida-1;j++){
salsa [i] [j] =sn.nextInt();
System.out.print (salsa [i] [j]);
ps.print(salsa [i] [j]);
}
System.out.println();
ps.println();
}
//suma de matriz // suma diagonal
int x,y,z;
x= salsa [0] [0];
y= salsa [1] [1];
z= salsa [2] [2];
System.out.print(x+y+z);
ps.print(x+y+z);
}
}
No hay comentarios:
Publicar un comentario