public static void main(String[] args) { int[] nums = {1,2,3,9}; //求数组最大值 int maxN = nums[0]; for(int i =1;i<nums.length;i++) { if (maxN < nums[i]) { maxN = nums[i]; } } System.out.println("最大值:"+maxN); }
public static void main(String[] args) { int[] nums = {1,2,3,9}; //数组的复制 int[] cpNums = new int[nums.length]; for(int i =0;i<cpNums.length;i++) { cpNums[i] = nums[i]; } System.out.println(Arrays.toString(cpNums)); }
public static void main(String[] args) { int[] nums = { 1, 2, 3, 9 }; // 数组的反转 int[] reversNums = new int[nums.length]; for (int i = nums.length - 1; i >= 0; i--) { reversNums[nums.length - 1 - i] = nums[i]; } System.out.println(Arrays.toString(reversNums)); //方式2 for (int i = 0, j = nums.length - 1; i < nums.length / 2; i++, j--) { //交换 int temp = nums[i]; nums[i] = nums[j]; nums[j] = temp; } System.out.println(Arrays.toString(nums)); }
原文:https://www.cnblogs.com/angdh/p/14418987.html