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

I need to create a rectangle bubble with rounded corners with text inside, like
I know there are some like: Bubble sort Insertion sort Shell sort Merge sort
This is a self-explanatory question: Why does this thing bubble into my try catch's
I'd like my compact framework application to show a notification bubble ONLY when it's
Bubble sort is O(n) at best, O(n^2) at worst, and its memory usage is
I am implementing the bubble sort algorithm and I want it to be able
Is that thing using bubble sort? Or what exactly? How does it work in
I'm attempting to do a simple bubble sort code to get familiar with list/string
Do bubble sorts have any real world use? Every time I see one mentioned,
What is the most elegant way of bubble-sorting in F#? UPDATE As pointed out

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.