java - Passing a string between voids -


i'm new java , i'm not sure if ask question right. have 2 voids, in second 1 string , want use main void. code that:

public void oncreate(bundle savedinstancestate) {  shuffle();  //here want use string correctanswer } public void shuffle() {  string correctanswer = "whatever"; } 

if want use string calculated in second function, why use void?

public void oncreate(bundle savedinstancestate) {     string s = shuffle();     //use s; }  public string shuffle() {     string correctanswer = "whatever";     return correctanswer; } 

you make correctanswer instance variable:

private string correctanswer;  public void oncreate(bundle savedinstancestate) {     shuffle();     //use instance variable correctanswer; }  public void shuffle() {     correctanswer = "whatever"; } 

Comments

Popular posts from this blog

javascript - Iterate over array and calculate average values of array-parts -

iphone - Using nested NSDictionary with Picker -

objective c - Newbie question -multiple parameters -