import java. util. Arrays;
public class Test01 {
public static void sort ( int [ ] a) {
int temp= 0 ;
for ( int i = 0 ; i < a. length- 1 ; i++ ) {
for ( int j = 0 ; j < a. length- 1 - i; j++ ) {
if ( a[ j] > a[ j+ 1 ] ) {
temp= a[ j] ;
a[ j] = a[ j+ 1 ] ;
a[ j+ 1 ] = temp;
}
}
}
return ;
}
public static void sort1 ( int [ ] a) {
int temp= 0 ;
for ( int i = 0 ; i < a. length- 1 ; i++ ) {
for ( int j = 0 ; j < a. length- 1 - i; j++ ) {
if ( a[ j] < a[ j+ 1 ] ) {
temp= a[ j] ;
a[ j] = a[ j+ 1 ] ;
a[ j+ 1 ] = temp;
}
}
}
return ;
}
public static void main ( String[ ] args) {
int [ ] a= { 3 , 2 , 5 , 45 , 3 , 23 , 87 , 345 } ;
sort ( a) ;
System. out. println ( Arrays. toString ( a) ) ;
System. out. println ( "=====================" ) ;
int [ ] b= { 55 , 4 , 1 , 34 , 53 , 3 , 767 , 8 } ;
sort1 ( b) ;
System. out. println ( Arrays. toString ( b) ) ;
}
}
运行结果:
```java
D: \tool\jdk- 12.0 .2 _windows- x64_bin\jdk- 12.0 .2 \bin\java. exe "-javaagent:D:\IDEA1\IntelliJ IDEA 2020.2\lib\idea_rt.jar=51169:D:\IDEA1\IntelliJ IDEA 2020.2\bin" - Dfile. encoding= UTF- 8 - classpath D: \IDEA1\javaSE\out\production\基础语法 practice. Test01
[ 2 , 3 , 3 , 5 , 23 , 45 , 87 , 345 ]
== == == == == == == == == == =
[ 767 , 55 , 53 , 34 , 8 , 4 , 3 , 1 ]
Process finished with exit code 0