   need help in a math problem
  There is a string array like the one down below://the longest string should be "310" and the shortest one should be "3","1" or "0"String[] results = {"310","3", "1", "10"};so as in the array above, the final results should be printed like this:(there is 6 different combinations)331133101311131003110310my program runs well untill when the array has a longer length(over 6) & set all its members to "310", the progam doesnt act ok and starts to print weired results..this is the way i did: public Vector doCal(Vector v,int index,String[] results){if(index < results.length){Vector result = new Vector(); for(int i = 0 ; i < v.size() ; i++){for(int j = 0 ; j < results[index].length() ; j++){String temp = (String) v.elementAt(i);result.addElement(temp+String.valueOf(results[index].charAt(j)));}}return doCal(result,index+1,results);}return v;}in the main method:Vector vec1 = new Vector();vec.addElement("");Vector vec2 = t.doCal(vec,0,forTest);for(int i = 0 ; i < result.size() ; i++){System.out.println(result.elementAt(i).toString());}Could anyone here tell me where i did wrong and how to solve it? thanks!   
  The results look ok to me. I added the following code to test it:import java.util.*;public class test {  public Vector doCal(Vector v,int index,String[] results){    if (index < results.length) { Vector result = new Vector(); for(int i = 0 ; i < v.size() ; i++){   for(int j = 0 ; j < results[index].length() ; j++){String temp = (String) v.elementAt(i);result.addElement(temp+String.valueOf(results[index].charAt(j)));   } } return doCal(result,index+1,results);    }    return v;  }  public static void main(String[] args) {    Vector init = new Vector();    init.add("");    Vector result = new test().doCal(init, 0, args);    for (Iterator i = result.iterator(); i.hasNext();) { System.out.println(i.next());    }  }}  Are you sure you're calling it right? (In particular, don't reuse the vector between calls) You might be better off adding a helper function to "set up". That said, you don't really need recursion for this. I would write it like this:Vector appendEachCharOf_To(String of, Vector to) {  Vector result = new Vector();  for (Iterator i = to.iterator(); i.hasNext();) {    String tmp = (String)(to.next());    for (int j = 0; j < of.length(); ++j) { // You don't need a String evaluation; you can append a char to a String // directly. result.addElement(tmp + of.charAt(j));    }  }  return result;}Vector generateAllCombinations(String[] source) {  Vector result = new Vector();  result.addElement("");  for (int i = 0; i < source.length; ++i) {    result = appendEachCharOf_To(source, result);  }  return result;}