Bubble Sort Question.
Hello,
I am a brand new to java programming (computer programming of any language period) and am starting to learn the language on my own. (I can not afford classes so I have to pick up a book and self learn). I am attempting to sort an array of numbers and can't seem to figure out why the last number in my array is not printing out. Can someone please help. Here's my code:
class sorter{
publicstaticvoid main(String args[]){
int theList[] ={10, 1, 9, 2, 8, 3, 7, 4, 6, 5};
int temp;
for(int i = 0; i < theList.length; i++){
for(int j = i + 1; j < theList.length; j++){
if(theList[i] < theList[j]){
temp = theList[i];
theList[i] = theList[j];
theList[j] = temp;
}
}
}
for(int x = 0; x < theList.length - 1; x++)
System.out.println(theList[x]);
System.out.println(theList.length-1);
}
}
The output I get is:
1
2
3
4
5
6
7
8
9
9 // repeats this number, rather than print the 10
Any assistance would be appreciated. Thanks in advance.
Vance.

