Java当中的数组

时间:2014-05-25 03:20:48   收藏:0   阅读:332

1. 数组的类型

2. 数组的定义方法

3. 数组的操作方法

 

1. 数组的类型

bubuko.com,布布扣
1 class Test{
2     public static void main(String args []){
3         int arr [] = {5,6,7,2,34,3,5,34,5,4};   //数组静态定义法
4         for(int i=0;i<arr.length;i++){
5             System.out.println(arr[i]);
6         }
7     }
8 }
bubuko.com,布布扣
bubuko.com,布布扣
1 class Test{
2     public static void main(String args []){
3         //int arr [] = {5,6,7,2,34,3,5,34,5,4}; 
4         int arr [] = new int[10] ;   //数组动态定义法
5         for(int i=0;i<arr.length;i++){
6             System.out.println(arr[i]);   //将会打印出10个0 
7         }
8     }
9 }
bubuko.com,布布扣

二维数组

1 class Test{
2     public static void main(String args []){
3         int arr [][]={{1,2,3},{4,5,6},{7,8,9}}; //注意里面也是花括号
4         System.out.println(arr[1][1]);  //arr[1]代表{4,5,6}.arr[1][1]代表5
5     }
6 }

二维数组打印

bubuko.com,布布扣
 1 class Test{
 2     public static void main(String args []){
 3         int arr [][]={{1,2,3},{4,5,6},{7,8,9}}; 
 4         for(int i=0;i<arr.length;i++){   //这里值得注意下!!!
 5             for(int j=0;j<arr[i].length;j++){
 6                 System.out.println(arr[i][j]);
 7             }
 8         }          
 9     }
10 }
bubuko.com,布布扣

 

Java当中的数组,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!