Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

when implemented my bubble sort outputs garbage and not the list

$
0
0
i need the list of numbers to end up being the output and instead it outputs something like this [I@7f1bfcfc

import java.util.Scanner;

public class BubbleSort
{ 
public static void main(String[] args)
  {
    Scanner input = new Scanner(System.in);
    int [] bubbles = new int [10];
    for (int i = 0; i < bubbles.length; i++)
      {
        System.out.println("Enter 10 numbers in any order: ");
        bubbles[i] = input.nextInt();
      }
      bubbleSort(bubbles);
  }
 
public static void bubbleSort(int[] bubbles) 
  {
      boolean swapped = true;
      int j = 0;
      int temporary;
    while (swapped) 
      {
        swapped = false;
        j++;
        for (int i = 0; i < bubbles.length - j; i++)
        {                                       
           if (bubbles[i] > bubbles[i + 1]) 
           {                          
               temporary = bubbles[i];
               bubbles[i] = bubbles[i + 1];
               bubbles[i + 1] = temporary;
               swapped = true;
           }
        }                
      }
    System.out.print(bubbles + "\n");
  }
}


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>