反转数组的元素

时间:2017-07-31 18:48:33

标签: java arrays exception-handling reverse

我的代码正在生成sampleTableColumns:[ {Header: 'Author', accessor: 'author'}, { Header: 'Books', accessor: 'books' render: (rowInfo) => { return ( <span> {rowInfo.value.map(book => (<span>{book.title}</span>))} </span> }, }, ], 异常。如何删除它?

3 个答案:

答案 0 :(得分:1)

更改,

System.out.println(arr[n]);

为:

System.out.println(Arrays.toString(arr));

答案 1 :(得分:1)

的System.out.println(ARR [N]); 这是问题,因为没有索引&#34; n&#34; n是元素的数量 你必须将表格0循环到n-1

    for(int i =0;i < n;i++){
System.out.println(arr[i]);

}

答案 2 :(得分:0)

您的代码可以正常反转元素数组,但由于System.out.println(arr [n])引发了arrayIndexOutOfBound异常。记住数组索引从零开始。对于n大小的数组,范围将是[0,(n-1)],即,如果n = 5,则范围将是0到4.

    <!doctype html>
      <html>
       <head>
         <script type="text/javascript" >
                function load() {
                     var div = document.getElementById('data');
                        div.innerHTML = div.innerHTML + "Write your New Data" + "<br>";
                      }
         </script>

      <body onload="load()">
         <div id= "data">
             Hello... I am old
         </div>
      </body>
    </html>