堆
初始化
package array;
public class Demo {
public static void main(String[] args) {
//动态初始化,
int[] num=new int[10];
System.out.println(num[0]);
//0
//静态初始化
int[] num2={1,2,3};
System.out.println(num2[0]);
}
}
数组的反转
package array;
public class Demo2 {
public static void main(String[] args) {
int[] nums={1,2,3};
int[] rev=reverse(nums);
printArray(rev);
}
public static void printArray(int[] nums){
for (int num:nums){
System.out.println(num);
}
}
public static int[] reverse(int[] nums){
int[] reverse=new int[nums.length];
for (int i=0,j=nums.length-1;i<nums.length;i++,j--){
reverse[j]=nums[i];
}
return reverse;
}
}
二维数组
package array;
public class Demo3 {
public static void main(String[] args) {
int[][] nums={{1,3},{3,2},{3,1}};
for (int i=0;i< nums.length;i++){
for(int j=0;j<nums[i].length;j++){
System.out.println(nums[i][j]);
}
}
}
}