Advertisement
Guest User

main

a guest
Nov 12th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.27 KB | None | 0 0
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.nio.file.Files;
  5. import java.nio.file.Paths;
  6.  
  7.  
  8. public class Pri {
  9.  
  10.     public static void main(String[] args) {
  11.          
  12.         int c=0;
  13.         int h=0;
  14.         int m=0;
  15.         List<String> data = null;
  16.         try {
  17.             data = Files.readAllLines(Paths.get("mate.txt"));
  18.         } catch (IOException e) {
  19.             System.out.println("No puede leer archivo");
  20.         }
  21.  
  22.         int[][] myArray = new int[data.size()][];
  23.         for (int i = 0; i < data.size(); i++) {
  24.             String[] temp = data.get(i).split(" ");
  25.             int[] values = new int[temp.length];
  26.             for (int j = 0; j < values.length; j++) {
  27.                 values[j] = Integer.parseInt(temp[j]);
  28.                 h=h+1;
  29.                
  30.             }
  31.             m=h;
  32.             h=0;
  33.             c=c+1;
  34.             myArray[i] = values;
  35.         }
  36.  
  37.         for (int i = 0; i < myArray.length; i++) {
  38.             System.out.println(myArray[i].length);
  39.         }
  40.         System.out.println("c: "+c);
  41.         System.out.println("m: "+m);
  42.  
  43.         try {
  44.             Scanner input = new Scanner(new File("mate.txt"));
  45.            
  46.             int n = c;
  47.             int[][] a = new int[n][m];
  48.             while (input.hasNextLine()) {
  49.                 for (int i = 0; i < n; i++) {
  50.                     for (int j = 0; j < m; j++) {
  51.                        try{                    
  52.                         a[i][j] = input.nextInt();
  53.                         //   System.out.println("n: "+ a[i][j]);
  54.                         }
  55.                        catch (java.util.NoSuchElementException e) {
  56.                            // e.printStackTrace();
  57.                         }
  58.                     }
  59.                 }         //print the input matrix
  60.                 System.out.println("matriz : \n");
  61.                 for (int i = 0; i < (n); i++) {
  62.                     System.out.print((char)124+" ");
  63.                     for (int j = 0; j < m; j++) {
  64.                         System.out.print(a[i][j]+" ");
  65.    
  66.                     }
  67.                     System.out.println((char)124+" ");
  68.                 }
  69.             }
  70.         } catch (Exception e) {
  71.             e.printStackTrace();
  72.         }
  73.     }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement