冒泡写法
public class Test {
public static void main ( String[ ] args) {
int [ ] arr= { 1 , 5 , 3 , 8 , 6 , 4 , 2 , 89 , 12 , 11 } ;
for ( int i = 0 ; i < arr. length; i++ ) {
for ( int j = 0 ; j < arr. length- i- 1 ; j++ ) {
if ( arr[ j ] > arr[ j + 1 ] ) {
int temp= arr[ j] ;
arr[ j] = arr[ j+ 1 ] ;
arr[ j+ 1 ] = temp;
}
}
}
System. out. println ( "排序后的顺序是:" ) ;
for ( int a : arr) {
System. out. print ( a+ " " ) ;
}
}
}
99乘法表
public class Test01 {
public static void main ( String[ ] args) {
for ( int i = 1 ; i <= 9 ; i++ ) {
for ( int j = 1 ; j <= i ; j++ ) {
System. out. print ( j+ "*" + i+ "=" + j* i+ " " ) ;
}
System. out. println ( "\n" ) ;
}
}
}
打印菱形
public class Test01 {
public static void main ( String[ ] args) {
for ( int i = 1 ; i <= 5 ; i++ ) {
for ( int j = 1 ; j <= i ; j++ ) {
System. out. print ( "*" ) ;
}
System. out. println ( "\n" ) ;
}
}
}
倒菱形
public class Test01 {
public static void main ( String[ ] args) {
for ( int i = 5 ; i >= 0 ; i-- ) {
for ( int j = 5 ; j > 5 - i ; j-- ) {
System. out. print ( "*" ) ;
}
System. out. println ( "\n" ) ;
}
}
}
打印菱形
public class Test01 {
public static void main ( String[ ] args) {
for ( int i = 1 ; i <= 5 ; i++ ) {
for ( int j = 1 ; j <= 5 - i ; j++ ) {
System. out. print ( " " ) ;
}
for ( int j = 1 ; j <= 2 * i- 1 ; j++ ) {
System. out. print ( "*" ) ;
}
System. out. println ( "\n" ) ;
}
for ( int i = 4 ; i >= 1 ; i-- ) {
for ( int j = 1 ; j <= 5 - i ; j++ ) {
System. out. print ( " " ) ;
}
for ( int j = 1 ; j <= 2 * i- 1 ; j++ ) {
System. out. print ( "*" ) ;
}
System. out. println ( "\n" ) ;
}
}
}