O código abaixo é para a leitura de um arquivo .txt, e a armazenagem de seus valores em vetores de inteiros. O problema é que o código pára de executar depois do primeiro for. A saída exibida é: O numero de deposito eh:5.
Desculpem o algoritmo é grandinho mas prefero postar ele completo porque não identifiquei o erro;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class Trabalho {
public static void main(String[] args) {
try{
BufferedReader in = new BufferedReader(new FileReader("entrada.txt"));
String str;
int numDepositos = 0;
int somaVetor1 = 0;
int somaVetor2 = 0;
str = in.readLine();
numDepositos = Integer.parseInt( str );
System.out.println("O numero de deposito eh:" + numDepositos);
int vetor1[] = new int[numDepositos];
int[] vetor2 = new int[numDepositos];
String[] array_depositos;
for(int i = 0; i < numDepositos; i++){
str = in.readLine();
array_depositos = str.split(" ");
vetor1[i] = Integer.parseInt( array_depositos[0] );
vetor2[i] = Integer.parseInt( array_depositos[1] );
somaVetor1 = vetor1[i] + somaVetor1;
somaVetor2 = vetor2[i] + somaVetor2;
//System.out.println(str);
}
if( somaVetor1 < somaVetor2 ){
int diferenca = somaVetor2 - somaVetor1;
System.out.println("Zezinho recebeu " + diferenca + " a mais que Joaozinho!");
}
if( somaVetor1 == somaVetor2 ){
System.out.println("Zezinho e Joaozinho receberam o mesmo valor");
}
if( somaVetor2 < somaVetor1 ){
int diferenca = somaVetor1 - somaVetor2;
System.out.println("Joaozinho recebeu " + diferenca + " a mais que Zezinho!");
}
//in.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
