Skip to main content
gamedev.net
🔒 Locked

A Combination problem..

Started by payne_roc Jun 5, 2006 at 5:50 AM 0 replies 600+ views
Original Post
payne_roc
payne_roc
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) 3311 3310 1311 1310 0311 0310 my 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!
Zahlman
Zahlman
I answered this in For Beginners. Please don't cross-post.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.