传入参数,动态的组织N个数组的所有对数

来源:互联网 发布:阿里云快照怎么用 编辑:程序博客网 时间:2024/05/16 09:59
  1. package cn.com.jdlssoft.daup.app.handlers.sjy;
  2. public class Jun {
  3.     /**
  4.      * @param args
  5.      */
  6.     public static void main(String[] args) {
  7.         // TODO Auto-generated method stub
  8.         // String a[] = {"1","2","3"};
  9.         // String b[] = {"4","5","6"};
  10.         // String c[] = {"7","8","9"};
  11.         // int count = 0;
  12.         // for(int i=0;i<a.length;i++){
  13.         // for(int j=0;j<b.length;j++){
  14.         // for(int k=0;k<b.length;k++){
  15.         // count ++;
  16.         // System.out.println(a[i]+":"+b[j]+":"+c[k]);
  17.         //                  
  18.         // }
  19.         // }
  20.         // }
  21.         // System.out.println(count);
  22.         String saveArray[] = {};// 最终保存的数组
  23.         String tempArray[] = {};// 临时数组,用于比较
  24.         //String yaos = "cp,1;cp,2;";
  25.         String yaos = "cp,1;cp,2;cp,2;cp,2;cp,2;cp,2;cp,2;:ycl,3;ycl,4;:dn,5;dn,6;:bb,7;bb,8";
  26.         //String yaos = "cp,1;:ycl,3;ycl,4;:dn,5;dn,6;:bb,7;";
  27.         String a[] = yaos.split(":");
  28.         for (int i = a.length - 1; i <= a.length - 1; i--) {
  29.             if (a.length == 1) {
  30.                 System.out.println("只有一个,直接退出");
  31.                 tempArray = new String[1];
  32.                 tempArray[0] = a[i];
  33.                 break;
  34.             }
  35.             if (i == -1) {
  36.                 break;
  37.             }
  38.             if (i == a.length - 1) {
  39.                 // 最后一个数组
  40.                 String hou_Arrray[] = a[i].split(";");
  41.                 // 最后一个的前一个数组
  42.                 String qian_Array[] = a[i - 1].split(";");
  43.                 System.out.println(a[i]);
  44.                 System.out.println(a[i - 1]);
  45.                 tempArray = new String[hou_Arrray.length * qian_Array.length];
  46.                 int tempint = 0;
  47.                 for (int j = 0; j < qian_Array.length; j++) {
  48.                     for (int k = 0; k < hou_Arrray.length; k++) {
  49.                         // System.out.println(qian_Array[j] + "&" +
  50.                         // hou_Arrray[k]);
  51.                         tempArray[tempint] = qian_Array[j] + "&"
  52.                                 + hou_Arrray[k];
  53.                         tempint++;
  54.                     }
  55.                 }
  56.                 System.out.println(tempArray.length);
  57.                 for (int j = 0; j < tempArray.length; j++) {
  58.                     System.out.println(j);
  59.                     System.out.println(tempArray[j]);
  60.                 }
  61.             } else {
  62.                 if (i - 1 != -1) {
  63.                     int tempint = 0;
  64.                     String qian_Array_1[] = a[i - 1].split(";");
  65.                     String temp_1[] = tempArray;
  66.                     tempArray = null;
  67.                     tempArray = new String[qian_Array_1.length * temp_1.length];
  68.                     for (int m = 0; m < qian_Array_1.length; m++) {
  69.                         for (int n = 0; n < temp_1.length; n++) {
  70.                             tempArray[tempint] = qian_Array_1[m] + "&"
  71.                                     + temp_1[n];
  72.                             tempint++;
  73.                         }
  74.                     }
  75.                 }
  76.             }
  77.         }
  78.         saveArray = tempArray;
  79.         System.out.println(saveArray.length);
  80.         
  81.         for(int i=0;i<saveArray.length;i++){
  82.             System.out.println("要死了:"+saveArray[i]);
  83.         }
  84.         
  85.     }
  86. }
原创粉丝点击