In a CSV file, the results of a race are stored in the format name: seconds. The program will convert this data into an ArrayList. Then the user will be asked how many data he wants to see (n) and the n participants will be listed with the best time; for that the runner will be looked for with the shortest time and will be eliminated from the ArrayList, until completing the list.
public static void main(String[] args) throws FileNotFoundException {
int numero = 0;
File f = new File("datos.dat");
Scanner fichero = new Scanner(f);
ArrayList<String> datos = new ArrayList();
String linea;
int t1=0;
while (fichero.hasNext()) {
linea = fichero.nextLine();
if (datos.size()==0){
datos.add(linea);
} else {
t1=Integer.parseInt(linea.substring(linea.indexOf(";")));
}
}
System.out.println(t1);
Scanner teclado = new Scanner(System.in);
numero = teclado.nextInt();
numero = numero - 1;
for (int i = 0; i <= numero; i++) {
System.out.println(datos.get(i));
}
}