.定义两个数组,首先把两个数组合并成一个新数组,然后把新数组中的所有元素逆序排列,需要实现的效果如图-2所示。

来源:互联网 发布:iphone一键刷机软件 编辑:程序博客网 时间:2024/06/05 17:09
package cn.bdqn09;public class S2 {public static void main(String[] args) {int[]a=new  int[]{10,20,30};int []b=new int[]{40,50,60};int[]c=new int[a.length+b.length];System.out.println("合并数组为:");for (int i = 0; i < c.length; i++) {if(i<a.length){c[i]=a[i];}else {c[i]=b[i-a.length];}System.out.print(c[i]+" ");}System.out.print("\n逆序为\n");for (int j =c.length-1;j>=0 ;j--) {System.out.print(c[j]+" ");}}}

0 0