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

# Thread: Bubble Sort Int Array Problem

1. ## 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. ## 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???