冒泡排序

public class BubbleSort 
{
	static int[] bubbleSort(int a[],int n)
	{
		int temp=0;
		for(int i=0;i<n;n--)
			for(int j=i;j<n-1;j++)			
			{
				if(a[j]>a[j+1])
				{
					temp = a[j];
					a[j] = a[j+1];
					a[j+1] = temp;
				}						
			}
	return a;					
	}
	public static void main(String[] args)
	{
		int a[] = new int[10];
		for(int i=0;i<10;i++)
		{
			a[i] =  (int) (Math.random()*10%10);//Math.random()返回一个介于0.0与1.0间的一个随机数
			System.out.print(a[i]+" ");
		}
		System.out.println();
		a = bubbleSort(a,10);		
		for(int i=0;i<10;i++)
		{			
			System.out.print(a[i]+" ");
		}
	}
}

你可能感兴趣的:(String,Class)