/**
* Created by rabbit on 2014-5-9.
*/
Class ArrayTest2 {
Public static void BubbleSort (int [] arr) // create a Bubble sorting method
{
For (int x = 0; x <arr. length-1; x ++)
{
For (int y = 0; y <arr. length-x-1; y ++) //-x is used to reduce the element-1 of each comparison in order to avoid cross-border. Exceeds the subscript range of the array.
{
If (arr [y] <arr [y + 1])
{
Int temp = arr [y];
Arr [y] = arr [y + 1];
Arr [y + 1] = temp;
}
}
}
}
Public static void PrintArr (int [] arr) // method for creating an output array element
{
For (int x = 0; x <arr. length; x ++)
{
If (x! = Arr. length-1)
{
System. out. print (arr [x] + ",");
} Else
System. out. print (arr [x]);
}
System. out. println ();
}
Public static void main (String [] args)
{
Int [] arr = {,-1}; // create an array and enter a value
PrintArr (arr); // call the Output Method
BubbleSort (arr); // call the Bubble sorting method
PrintArr (arr); // call the Output Method
}
}