Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.lang.*;
- import java.io.*;
- import java.nio.file.Files;
- import java.nio.file.Paths;
- public class Pri {
- public static void main(String[] args) {
- int c=0;
- int h=0;
- int m=0;
- List<String> data = null;
- try {
- data = Files.readAllLines(Paths.get("mate.txt"));
- } catch (IOException e) {
- System.out.println("No puede leer archivo");
- }
- int[][] myArray = new int[data.size()][];
- for (int i = 0; i < data.size(); i++) {
- String[] temp = data.get(i).split(" ");
- int[] values = new int[temp.length];
- for (int j = 0; j < values.length; j++) {
- values[j] = Integer.parseInt(temp[j]);
- h=h+1;
- }
- m=h;
- h=0;
- c=c+1;
- myArray[i] = values;
- }
- for (int i = 0; i < myArray.length; i++) {
- System.out.println(myArray[i].length);
- }
- System.out.println("c: "+c);
- System.out.println("m: "+m);
- try {
- Scanner input = new Scanner(new File("mate.txt"));
- int n = c;
- int[][] a = new int[n][m];
- while (input.hasNextLine()) {
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) {
- try{
- a[i][j] = input.nextInt();
- // System.out.println("n: "+ a[i][j]);
- }
- catch (java.util.NoSuchElementException e) {
- // e.printStackTrace();
- }
- }
- } //print the input matrix
- System.out.println("matriz : \n");
- for (int i = 0; i < (n); i++) {
- System.out.print((char)124+" ");
- for (int j = 0; j < m; j++) {
- System.out.print(a[i][j]+" ");
- }
- System.out.println((char)124+" ");
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement