赞
踩
1.for循环,倒序输出
- package day01;
-
- public class Rev {
- public static void main(String[] args) {
- int[]arr = {1,3,5,7,9};
- for (int i = arr.length-1; i >=0; i--) {
- System.out.print(arr[i]);
- }
- }
- }
2. 将最后一个值赋给第一个值
- package day01;
-
- public class Rev {
- public static void main(String[] args) {
- int[] arr = {1,3,5,7,9};
- int[] newArr =new int[arr.length];
- for(int i = 0,j=arr.length-1;i<arr.length;i++,j--){
- newArr[i]= arr[j];
- System.out.print(newArr[i]);
- }
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。