Results 1 to 3 of 3
  1. #1
    incxx is offline Member
    Join Date
    Mar 2013
    Posts
    21
    Rep Power
    0

    Default Bubble Sort Java help!

    The program is supposed to generate 20 random numbers then store them into an array. it will then sort the numbers into descending order and then output the sorted array onto the screen.

    When I compile my code, it says that it cannot find the symbol for the swap method. Can someone please help me fix this! Thanks :)

    THIS IS MY CODE:
    import java.io.*;

    public class bubbleSort
    {

    public static void main (String [] args) throws IOException
    {
    int arrayNum [] = new int [20];


    System.out.println("Original Arrays:");
    for (int counter = 0; counter < arrayNum.length; counter++)
    {
    arrayNum [counter] = (int)(Math.random()*100) + 1;
    System.out.println("Array number " + counter + " is: " + arrayNum [counter]);
    }

    bubbleSort (arrayNum);

    System.out.println("Arrays in decscending order:");
    for (int counter = 0; counter < arrayNum.length; counter++)
    {
    System.out.println("Array number " + counter + " is: " + arrayNum [counter]);
    }
    }

    public static void bubbleSort (int arrayNum2 [])
    {
    for (int run = 1; run < arrayNum2.length; run++)
    {
    for (int num = 0; num < arrayNum2.length-1; num++)
    {
    if (arrayNum2 [num] < arrayNum2 [num + 1])
    {
    swap (arrayNum2, num, num + 1);
    }
    }
    }
    }
    public static void swapNum (int arrayNum3 [], int one, int two)
    {
    int hold;

    hold = arrayNum3 [one];
    arrayNum3 [one] = arrayNum3 [two];
    arrayNum3 [two] = hold;
    }
    }

  2. #2
    GregBrannon is offline Member
    Join Date
    Mar 2013
    Location
    Southern Maryland, USA
    Posts
    5
    Rep Power
    0

    Default Re: Bubble Sort Java help!

    The method is called swapNum() not swap(). Change the name and that error will be corrected.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

    Default Re: Bubble Sort Java help!

    You were told about the code tags in your previous thread*, and I provided a couple of links for you. If you're not going to follow responses, why bother to ask for help on a forum?

    * Did I use arrays right in my Java code?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Bubble sort Algorithm
    By Hotspotmar in forum New To Java
    Replies: 1
    Last Post: 06-06-2012, 08:38 AM
  2. Bubble sort
    By pineapple in forum New To Java
    Replies: 3
    Last Post: 04-25-2009, 01:45 AM
  3. How to sort a list using Bubble sort algorithm
    By Java Tip in forum Algorithms
    Replies: 3
    Last Post: 04-29-2008, 09:04 PM
  4. Bubble Sort in Java
    By Java Tip in forum Algorithms
    Replies: 0
    Last Post: 04-15-2008, 08:42 PM
  5. need help with bubble sort
    By lowpro in forum New To Java
    Replies: 3
    Last Post: 12-17-2007, 06:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •