【问题标题】:how do i remove the space at at the end of the column header?如何删除列标题末尾的空格?
【发布时间】:2015-02-28 00:07:08
【问题描述】:

//我想知道如何去掉列头末尾的空格?

公共类布尔{

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" ); 
        }
        }

【问题讨论】:

  • 您说的是哪个列标题?你试过什么??

标签: java arrays for-loop


【解决方案1】:
for ( int j = 0; j < a.length - 1; j++ ) {
       System.out.print( j + 1 + " " );              
}
System.out.print( a.length );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-26
    • 2017-11-15
    • 1970-01-01
    • 2015-12-05
    相关资源
    最近更新 更多