how to reuse method returned string ??
Hello friends,
I am writing a small program in which i have 3 methods. All are working fine. One of the method getstring(char_aarray, string, int_array) is taking 3 arguments First arguments is char[ ] and returning a character array char[ ]. I want that when the program start and there is a call to getstring(char_rarray, string, int_array) method, it takes a predefined char[ ] as arguemnt but second time if there is call to that method it uses its own returned char[ ].
Thanks in advance.
BR,
zeeshan
Re: how to reuse method returned string ??
Show me your program once.....
Regards,
guptapr
Re: how to reuse method returned string ??
I am trying to develop a hangman game. the code is right here.
Code :
import java.util.Vector;
public class SearchChar {
public static void main(String args[]){
String main= new String("zeeshannabeel");
String search= new String("e");
String s= printdash(main);
char[] prestring= s.toCharArray();
Vector<Integer> vectorarray= getindex(main, search);
char[] searcharray= search.toCharArray();
char[] strings= guess(prestring,searcharray,vectorarray);
System.out.println(strings);
}
/* --- To print dash first time --- */
public static String printdash(String main){
String dash= new String();
for(int z=0; z<main.length(); z++){
dash= dash.concat("-");
}
System.out.println(dash);
return dash;
}
/* --- To find the IndexOf search string in Main string --- */
public static Vector<Integer> getindex(String main, String search){
Vector<Integer> varray= new Vector<Integer>();
for(int i=0; i<=main.lastIndexOf(search); i++){
varray.addElement(main.indexOf(search, i));
i= main.indexOf(search, i);
}
/* --- To print indexOf Search string in Main string --- */
for(int a=0; a<varray.size(); a++){
System.out.println(varray.get(a));
}
return varray;
}
/*------ To insert Search character in String --- */
public static char[] guess(char[]pre_string, char[]guess_string, Vector<Integer> vectorarray){
int j=0;
while(j<vectorarray.size()){
int k=vectorarray.elementAt(j);
for(int i=0; i<guess_string.length; i++){
pre_string[k]= guess_string[i];
k++;
}
j++;
}
return pre_string;
}
}
Re: how to reuse method returned string ??
Just store the array it returns and pass it back into it the second time.
Chris
Re: how to reuse method returned string ??
ofcourse i know that i have to store the array and pass it back to the second time ... but how? this is my question. I have stored that arrayin char[] strings as u can see in my code. but how can i reuse it second third fourth untill char[] strings matches to char[] main. But remember call to the method depends on if the search string changes.
BR,
Zeeshan
Re: how to reuse method returned string ??
I cannot see your getstrig method :/
Chris
Re: how to reuse method returned string ??
there is no getstring method. I just wrote a fake name. The name of that method in code is guess method with 3 arguments. anyways thats for ur help :) i have solved the problem :)
Re: how to reuse method returned string ??
Next time just use the name of the method, it avoids confusion.
Glad you have sorted it, mark as solved if that is everythin.
Thanks,
Chris
The Moderation Team...
Always wanted to say that lmao!