+ 6
Why is this code not working?
I learned from "Learn" section that ojs, arrays and Strings are reference type values. So, when we pass them as arguments then if the method wants then it may change their original value. https://code.sololearn.com/cPhz3o2i6iqt/?ref=app
7 Answers
+ 3
bro , in this program
method "celebratebirthday" does not return any value ....thats why u hv used keyword "void" before it
but in the other program , setString method returns a value ,,, so u must not use void in front of that method and also make use of return statement in it
+ 5
Probably because there was no return value to your statement.
Also, when you call a function, unless ypu replave the value, the function does nothing.
Oh you could probably use globals
+ 5
Ok, Gaurav. I think I understand it now. Thanks for your help.đ
+ 5
David, actually that's not what I wanted to do. I wanted to change the actual String "s" by passing it as an argument to a method. Thanks for your time though.đđ
+ 1
If I HAVE to use return in these kind of codes then how come this program is working:?
https://code.sololearn.com/cz5Ws94wTrmU/?ref=app
+ 1
Im not 100% sure what your intending to do so i fixed a few bits maby you can work of this...
public class Program{
static void changeString(String st){System.out.println(st);}
public static void main(String[] args) {
Program pro = new Program();
String s = "Java";
System.out.println (s);
if(s.equals("Java")){
pro.changeString("Guava");}
}
}
0
ah right i see. did you manage to do it?