---
title: "排序算法－冒泡排序"
author: "fyc92"
date: "2013-10-28T14:14:24Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2013-10-28T14:15:02Z"
id: 1965627
url: "https://fyc92.iteye.com/blog/1965627"
---

```java
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int a[] = {2,5,8,12,21,30,44,55,63,63,65};
		int length = a.length;
		int times = 0;
		boolean isChange = false;
		for (int i = length - 1; i > 0; i--) {
			for (int j = 0; j < i; j++) {
				if (a[j] > a[j+1]) {
					int tmp = a[j];
					a[j] = a[j+1];
					a[j+1] = tmp;
					times++;
					isChange = true;
				}
			}
			if(!isChange)
				break;
		}
		System.out.println("times = "+times);
		for (int i = 0; i < length; i++) {
			System.out.print(a[i]+",");
		}
	}
```