Olá pessoal, blz ?
Então venho pedir auxílio p/ vcs por que meu código tem um erro e eu não consigo encontrar.
Tenho um arquivo mat1.txt e o conteúdo dele é este :
[telefone removido]
[telefone removido]
[telefone removido]
[telefone removido]
[telefone removido]
[telefone removido]
[telefone removido]
[telefone removido]
[telefone removido]
[telefone removido]
[telefone removido]
Estou tentando fazer este conteúdo entrar numa matriz inteira mas, algo está errado :
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class LerArquivo
{
public static void main(String[] args) throws IOException
{
int l = 11, c = 11;
int matriz[][] = new int[l][c];
try
{
InputStream entrada = new FileInputStream("C:\Users\Jorge Luis\Desktop\mat1.txt");
InputStreamReader reader = new InputStreamReader(entrada);
BufferedReader buffer = new BufferedReader(reader);
String texto = buffer.readLine();
while((texto = buffer.readLine()) != null)
{
for(int i = 0;i < matriz.length;i++)
{
for(int j = 0; j < matriz.length;j++ )
{
matriz[i][j] = Integer.parseInt(texto);
}
}
}
for(int i = 0;i < matriz.length;i++,System.out.println("\n"))
{
for(int j = 0; j < matriz.length;j++ )
{
System.out.print(matriz[i][j]+" ");
}
}
}
catch (FileNotFoundException e)
{
e.getMessage();
}
}
}
O correto seria a minha matriz ser preenchida com os dados do .txt mas, o console me mostra que os dados foram preenchidos errados :
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
preciso calcular do ponto central da matriz (matriz[5][5]) até aonde se encontram os números 1 ,a fórmula que vou usar é esta :a² = b² +c², e as respostas no console tem que ser: a = 2, a = 5
Alguém poderia dar uma força ? desde já agradeço !