Java实现图形界面输入输出

Graph

新学期开始了,一定要好好学习,天天熬夜!

Java冒泡排序算法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
public class Maopao {
public void bigAndSmall(){
int arr[] = {-1,3,6,7,0,12,35,5,4,666};
/*根据数组的长度循环遍历,并判断如果前一个值小于后一个值,
那么就把“后一个值”排列到“当前前一个值”的前面。*/
for (int i=1;i<arr.length;i++){
System.out.println("当i="+i+"时:");
for (int j=0;j<arr.length-i;j++){
if (arr[j]<arr[j+1]){
int temp;
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
System.out.println("当j="+j+"时:"+arr[0]+","+arr[1]+","+arr[2]+","+arr[3]+","+arr[4]+","+arr[5]+","+arr[6]+","+arr[7]+","+arr[8]+","+arr[9]);
}
System.out.println("FOR循环结果为:"+arr[0]+","+arr[1]+","+arr[2]+","+arr[3]+","+arr[4]+","+arr[5]+","+arr[6]+","+arr[7]+","+arr[8]+","+arr[9]);
System.out.println("____________________________________");
}
for (int i=0;i<arr.length;i++){
System.out.println(arr[i]);
}
}
public static void main(String args[]){
//main函数中,通过实例化别名点方法名的方式调用并打印出结果
Maopao mp = new Maopao();
mp.bigAndSmall();
}
}
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×