<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                >[success] # 二維數組 * 二維數組本質上就是由多個一維數組摞在一起組成的數組,二維數組中 的每個元素都是一維數組,而一維數組中的每個元素才是數據內容,即`外層一維數組為行,內存的一維數組為列` * 二維數組的聲明 * * `數據類型[][] 數組名稱 = new 數據類型[行數][列數];` * * `數據類型[][] 數組名稱 = {{元素1, 元素2,...}, ...};` * 二維數組只聲明行不聲明列 ~~~ public class ArrayArrayTest { public static void main(String[] args) { // 先聲明行 int[][] ls = new int[2][]; // 后聲明列 ls[0] = new int[5]; ls[1] = new int[4]; } } ~~~ >[danger] ##### 二維數組聲明 * 聲明一個兩行兩列數組 ~~~ [ [0, 0], [0, 0] ] ~~~ ~~~ public class ArrayArrayTest { public static void main(String[] args) { int[][] ls = new int[2][2]; // [[0, 0],[0, 0]] int[][] ls1 = { { 0, 0 }, { 0, 0 } }; } } ~~~ >[danger] ##### 賦值并打印 ~~~ public class ArrayArrayTest { public static void main(String[] args) { int[][] ls = new int[2][2]; int count = 0; for (int i = 0; i < ls.length; i++) { for (int j = 0; j < ls[i].length; j++) { ls[i][j] = count++; } } // [[0, 1],[2, 3]] for (int i = 0; i < ls.length; i++) { for (int j = 0; j < ls[i].length; j++) { System.out.print(ls[i][j] + " "); // 0 1 2 3 } } } } ~~~ >[danger] ##### 楊輝三角形 ~~~ /* 編程使用二維數組來實現楊輝三角的生成和遍歷 */ import java.util.Scanner; public class ArrayArrayTriangleTest { public static void main(String[] args) { // 1.提示用戶輸入一個行數并使用變量記錄 System.out.println("請輸入一個行數:"); Scanner sc = new Scanner(System.in); int num = sc.nextInt(); // 2.根據用戶輸入的行數來聲明對應的二維數組 int[][] arr = new int[num][]; // 3.針對二維數組中的每個元素進行初始化,使用雙重for循環 // 使用外層for循環控制二維數組的行下標 for(int i = 0; i < num; i++) { // 針對二維數組中的每一行進行內存空間的申請 arr[i] = new int[i+1]; // 使用內層for循環控制二維數組的列下標 for(int j = 0; j <= i; j++) { // 當列下標為0或者列下標與當前行的行下標相等時,則對應位置的元素就是1 if(0 == j || i == j) { arr[i][j] = 1; } else { // 否則對應位置的元素就是上一行當前列的元素加上上一行前一列的元素 arr[i][j] = arr[i-1][j] + arr[i-1][j-1]; } } } // 4.打印最終生成的結果 for(int i = 0; i < num; i++) { for(int j = 0; j <= i; j++) { System.out.print(arr[i][j] + " "); } System.out.println(); } } } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看