Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3239832
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:00:57+00:00 2026-05-17T18:00:57+00:00

How do I do a bubble sort in java, The text file looks like

  • 0

How do I do a bubble sort in java,
The text file looks like this:

aaa

2

bbb

3

ccc

1

What I need to do is to loop through it and display the highest score to the lowest.
When I run the code below, The numbers, are already sorted. and it will display 3, 2, then 1.
But the name isn’t in sync with the corresponding score, it will only display the names based on what’s first. So the output will basically look like this, if I run the code below:

aaa  3

bbb  2

ccc  1

Function:

public void hi_score(){
    int i=0;
        try {
                 FileReader fr;
          fr = new FileReader (new File("F:\\pscores.txt"));
          BufferedReader br = new BufferedReader (fr);
          int ar=0;
          for(ar=0;ar<10;ar++){
          player_name[ar]=br.readLine();
          player_score[ar]=Integer.parseInt(br.readLine());
          }

            } catch (Exception e) { e.printStackTrace();}

              bubble_srt(player_score, player_score.length);
        System.out.print("Highscores:\n");
        System.out.println("Scores");

        System.out.println("Name\tScore");
        for(i = 0; i <NUMBER_OF_HI_SCORE; i++){
          System.out.print(player_name[i] + "\t" +player_score[i] + "\n");

        }
    }

How do I do this, without using arraylist. Just ordinary array.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T18:00:58+00:00Added an answer on May 17, 2026 at 6:00 pm

    Should create a single array that combines the player and the respective score as an String[];
    create a single array of scores that gets bubble sorted

    then as you have an sorted int[] player_score array, you can try to match it up via substring of the elements in String[] playername + score

    edit:
    so after the bubble sort, when you are going to print it, perhaps take the newly sorted array of scores, try to match with an appropriate element of the array of String[] playername + score, then print out the element that matches the 0th, 1st, 2nd values of the sorted score array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If this is Bubble sort then what is this ? Do you see the
My professor gave me the following definition of Shell Sort. I've included the Bubble
okay, I am beating myself up over this. I am need to load a
I'm looking for a bubblesort code in java that is opposite of the usual
What is the difference between straight selection sort vs. exchange selection sort ? I
I've looked through the developer.android.com and googled quite a bit, but I can't seem
Am trying to find the latest sub-directory from a parent director. public static DirectoryInfo
I am looking for book on data structure which guides in linked list, double
Lets say we have a problem we implemented using X algorithm with O(n) or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.