@ddanbe is right. Look at the last step of the cycle - j=9 is still less than 10 so it executes but you try to swap number[9] with number[10] which is out of range. Also I would do for(int j=0; j<9-i2; j++)
- the biggest number always gets to the end so you need to check 1 less number in the next step. It's easiest to imagine with the biggest number initially being in the first place - the check is true in every step of the 1st iteration and it always gets swapped. It ends up at the last place and you don't need to check it in the 2nd iteration (and so on).
ddanbe commented: Good explanation. +15