如何删除列标题末尾的空格?

时间:2015-02-28 00:07:09

标签: java arrays for-loop

//我想知道如何删除列标题末尾的空格?

public class Boolean {

public static void main(String[] args) {
    boolean[][] a = {{true, false, false, false, false}, 

                     {true, true, false, false, false}, 
                     {true, true, true, false, false}, 
                     {true, true, true, true, false},
                     {true, true, true, true, true}};                   

        for ( int j = 0; j < a.length; j++ ) {
           System.out.print( j + 1 + " " );              
        }                        
         System.out.println();
        for ( int i = 0; i < a.length; i++ ) {              
        for ( int j = 0; j < a[i].length; j++ ) {
           System.out.print( ( a[i][j] == true ) ? "* " : "  " );                
        }
            System.out.print( i + 1 + "\n" ); 
        }
        }

1 个答案:

答案 0 :(得分:0)

for ( int j = 0; j < a.length - 1; j++ ) {
       System.out.print( j + 1 + " " );              
}
System.out.print( a.length );