Hello,
i would like to add a highscore list to my sudoku game,
to save all scores i created a filewriter and wrote the scores into the .txt
but how can i manage to get the best times on the top? i thought of bubble sort, but i dont know how to only get the times back from the .txt
bubble sort
File Writer
FileReader
i would like to add a highscore list to my sudoku game,
to save all scores i created a filewriter and wrote the scores into the .txt
but how can i manage to get the best times on the top? i thought of bubble sort, but i dont know how to only get the times back from the .txt
bubble sort
void bubbleSort ()
{
for (int end = 10; end > 0;ende--)
{
for (int i = 0; i < end; i++)
{
if (scores[i]>scores[i+1])
{
int ablage = scores[i];
scores[i] = scores[i+1];
scores[i+1] = ablage;
}
}
}
File Writer
try{
// Create file
BufferedWriter out = new BufferedWriter(new FileWriter("out.txt"));
out.write("\t\t\tBestzeiten Top 10");
out.newLine();
String platz1 = " 1." + uhr.getText();
out.write(platz1);
out.newLine();
out.write(" 2.");
out.newLine();
out.write(" 3.");
out.newLine();
out.write(" 4.");
out.newLine();
out.write(" 5.");
out.newLine();
out.write(" 6.");
out.newLine();
out.write(" 7.");
out.newLine();
out.write(" 8.");
out.newLine();
out.write(" 9.");
out.newLine();
out.write("10.");
//Close the output stream
out.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
FileReader
try{
BufferedReader br = new BufferedReader(new FileReader("out.txt"));
for(int r=0; r<11;r++){
String zeile = br.readLine();
System.out.println(zeile);
System.out.println("");
}
br.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}