forse dopo svariati tentativi ho capito come fare a mettere la top 10.
ho messo una parte di codice di un Bubble Sort ( un codice che legge i dati e li ordina ) e sono arrivato a questo punto: ho fatto il bubblesort ho messo il BufferedReader e vorrei che quel che cè scritto nel file .txt venga elaborato dal bubbole sort.
codice:
String str ;
FileReader fr = null;
LineNumberReader lnr = null;
int i;
try{
fr = new FileReader("recordfile.txt");
lnr = new LineNumberReader(fr);
while((str=lnr.readLine())!=null)
{
i=lnr.getLineNumber();
System.out.print(i+"°: ");
System.out.println(str);
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(fr!=null)
fr.close();
if(lnr!=null)
lnr.close();
}
int [] numbers = {}; // dentro alle parentesi graffe vorrei mettere il String str che è lo string che rappresenta tutti i risultati
bubblesort(numbers);
}
static void bubblesort(int[] numbers)
{
int tempVar;
for (int i = 0; i < numbers.length; i++)
{
for(int j = 0; j < numbers.length; j++)
{
if(numbers[i] > numbers[j])
{
tempVar = numbers [j];
numbers [j]= numbers [i];
numbers [i] = tempVar;
}
}
}
for (int i = 0; i < numbers.length; i++)
{
System.out.println(numbers[i]);
}
}
come potrei mettere lo String str dentro all' int ?