Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Bubble Sort Int Array Problem

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Bubble Sort Int Array Problem

    the error says int cannot be deferenced at java line 11
    here is the code.
    how do i fix that?

    public class SortInt
    {
        public static void sort(int cases[])              //Sorting fuction, the array of nums is passed to it
        {
            int temp;                                    //a temp var is need to swtich the values in the array
     
            for(int i = 0; i < cases.length - 1; i++)        //Start of the bubble sort, you need to take one away from
            {                                               //the legnth of the array b/c you dont need to go throw the
                for(int j = 0; j < cases.length - 1; j++) //array that many times. Also if it whould go passt the end of
                {                                           //the array in the second loop wich whould not been good.
                    if(cases[j].compareTo(cases[j+1]) > 0)               //This part checks to see if the number before it is bigger
                                                                        //You must use the compareTo() method of a string
                    {                                       //Note: chage the < opprator to > to sort from samllest to lagergets
                        temp = cases[j];                    //Sotres the value of nums[ii] in the temp var for use latter
                        cases[j] = cases[j+1];              //puts the value of the bigger number where the lesser one was
                        cases[j+1] = temp;                  //puts the value of the lesser var back in the array where the
                    }                                       //biger one was.
                }
            }
        }
     
        public static void main(String[] args)
        {
             //declares an array to be sorted
             int[] cases = {200000 , 300000 , 100000 ,400000 , 500000 , 750000 , 1000000,
    		 1 , 2 , 5 ,400 ,500,750, 1000 ,
    		5000 , 10000 , 25000 , 10 , 25 , 50 , 75,
    		100 ,  50000 , 75000 };
     
             System.out.println("Before sort():\n");
             for(int i = 0; i < cases.length; i++)      //for loop to show all the values of the array
             {
                 System.out.println(cases[i]);          //uses the for loop index var to slect an array entreay
             }
     
             sort(cases);                               //sends the array to the sort() fuction
     
             System.out.println("\nAfter sort():\n");
             for(int i = 0; i < cases.length; i++)      //for loop to show the realostes of the sorting
             {
                 System.out.println(cases[i]);
             }
        }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,265
    Thanks
    56
    Thanked 2,372 Times in 2,343 Posts

    Default Re: Bubble Sort Int Array Problem

    Please post the full contents of the error message you get when you compile this program.

    Where is the line with the error? Which is Line 11???

Similar Threads

  1. Bubble Sort with random numbers
    By jake6047 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 20th, 2011, 10:39 AM
  2. Bubble Sort help
    By baueml01 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: June 5th, 2011, 09:47 PM
  3. bubble sort and selection sort on strings
    By Sir Saula in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 3rd, 2010, 10:44 AM
  4. Javascript Bubble Sort
    By Fidelacchius in forum What's Wrong With My Code?
    Replies: 17
    Last Post: May 24th, 2010, 05:43 PM
  5. bubble sort timer problem
    By JavaNoob82 in forum Algorithms & Recursion
    Replies: 1
    Last Post: March 12th, 2010, 09:22 AM