- class maopao
- {
- public static void main(String[] args)
- {
-
- int [] q = {99,8,7,48,41,85,41};
-
-
- paixu (q);
- dayin(q);
- }
- public static void paixu (int [] q)
- {
- for (int a = 0;a <= q.length-1;a++ )//总数有q.length个角标,本身不用比较,所以q.length-1
- {
- for (int b= 0; b<q.length-1-a;b++ )//除了本身还剃出了比较过的数
- {
-
- if (q[b] > q[b+1])
- {
- int tamp = 0;
-
- tamp = q[b];
- q[b] = q[b+1];
- q[b+1]= tamp;
-
- }
- }
-
- }
- }
- public static void dayin (int []q)
- {
- for (int a=0;a<=q.length-1 ;a++ )//因为角标存在0,所以是q.length-1.
- {
- if (a != q.length-1)
-
- System.out.print(q[a]+" "+"<"+" ");
- else
- System.out.print(q[a]);
- }
- }
- }
复制代码 |
|