Java基础06-二维数组
Created At : 2020-05-22 15:50
Count:1.3k
Views 👀 :
Demo1_Array 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 class Demo1_Array { public static void main (String[] args) { int [][] arr = new int [3 ][2 ]; System.out.println(arr); System.out.println(arr[0 ]); System.out.println(arr[0 ][0 ]); } }
Demo2_Array 1 2 3 4 5 6 7 8 9 10 11 12 13 class Demo2_Array { public static void main (String[] args) { int [][] arr = new int [3 ][2 ]; System.out.println(arr); System.out.println(arr[0 ]); System.out.println(arr[0 ][0 ]); } }
Demo3_Array 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 class Demo3_Array { public static void main (String[] args) { int [][] arr = new int [3 ][]; System.out.println(arr[0 ]); System.out.println(arr[1 ]); System.out.println(arr[2 ]); arr[0 ] = new int [3 ]; arr[1 ] = new int [5 ]; System.out.println("------------------" ); System.out.println(arr[0 ]); System.out.println(arr[1 ]); System.out.println(arr[2 ]); } }
Demo4_Array 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 class Demo4_Array { public static void main (String[] args) { int [][] arr = {{1 ,2 ,3 },{4 ,5 },{6 ,7 ,8 ,9 }}; System.out.println(arr); System.out.println(arr[0 ]); System.out.println(arr[0 ][0 ]); } }
Test1_Array 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 class Test1_Array { public static void main (String[] args) { int [][] arr = {{1 ,2 ,3 },{4 ,5 },{6 ,7 ,8 ,9 }}; for (int i = 0 ;i < arr.length ;i++ ) { for (int j = 0 ;j < arr[i].length ;j++ ) { System.out.print(arr[i][j] + " " ); } System.out.println(); } } }
Test2_Array 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 class Test2_Array { public static void main (String[] args) { int [][] arr = {{22 ,66 ,44 },{77 ,33 ,88 },{25 ,45 ,65 },{11 ,66 ,99 }}; int sum = 0 ; for (int i = 0 ;i < arr.length ;i++ ) { for (int j = 0 ;j < arr[i].length ;j++ ) { sum = sum + arr[i][j]; } } System.out.println(sum); } }
Test3_Array 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 class Test3_Array { public static void main (String[] args) { a = 10 ,b = 20 int [] arr = {1 ,2 ,3 ,4 ,5 }; change(arr); System.out.println(arr[1 ]); } public static void change (int a,int b) { System.out.println("a:" +a+",b:" +b); a = b; b = a + b; System.out.println("a:" +a+",b:" +b); } public static void change (int [] arr) { for (int x=0 ; x<arr.length; x++) { if (arr[x]%2 ==0 ) { arr[x]*=2 ; } } } }
转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 1210331079@qq.com
Title: Java基础06-二维数组
Count: 1.3k
Author: 千 羽
Created At: 2020-05-22, 15:50:47
Updated At: 2020-10-05, 08:51:26
Url: https://nateshao.github.io/2020/05/22/Java%E5%9F%BA%E7%A1%8006-%E4%BA%8C%E7%BB%B4%E6%95%B0%E7%BB%84/
Copyright: 'Attribution-non-commercial-shared in the same way 4.0' Reprint please keep the original link and author.