JoaoSkate Posted March 11, 2017 at 11:52 AM Report Share #603054 Posted March 11, 2017 at 11:52 AM Ola bom dia, estou a tentar ler um ficheiro .txt e criar uma matriz de boolean que fica a true nas posiçoes com o a string "=" , mas estou com algumas dificuldades, o ficheiro é deste tipo ========== = L L = # * # L * # = = # * # k = * = k * # X * ========== o que tentei foi: public boolean[][] readToMatrix() throws FileNotFoundException{ Scanner sc = new Scanner(new File("Pasta/ficheiro.txt")); String linha = ""; boolean[][] matriz = new boolean[10][10]; ArrayList<String> list = new ArrayList<String>(); while(sc.hasNextLine()){ linha = sc.nextLine(); list.add(linha); } sc.close(); int j = -1 ; for(String k : list){ j++; for(int i = 0 ; i < k.split("").length ; i++){ if(k.split("")[i] == "="){ matriz[i][j]== true; } else{ matriz[i][j]=false; } } } return matriz; } Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted March 11, 2017 at 07:28 PM Report Share #603062 Posted March 11, 2017 at 07:28 PM uma questao inicial. Como sabes qye a matriz a retornar e 10x10? IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
JoaoSkate Posted March 12, 2017 at 12:20 AM Author Report Share #603069 Posted March 12, 2017 at 12:20 AM (edited) os ficheiros que quero usar sao todos 10x10 à partida. mas secalhar é uma má pratica isso, nao sei Edited March 12, 2017 at 12:21 AM by JoaoSkate Link to comment Share on other sites More sharing options...
Guest Posted March 12, 2017 at 01:04 AM Report Share #603071 Posted March 12, 2017 at 01:04 AM Assumir é sempre má pratica. Palavra chave: à partida. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now