I believe you’re asking how to return a value from a function in Java. If I’m incorrect, disregard this response. When you declare the function DoSomething
, you need to also declare the type of the return value of the function. In this case, you would probably use int
, so the function would look more like:
int DoSomething(int Amount){
int i = Amount;
if (i=2){
i = 1;
}
return i;
}
And to receive a value from this function, you need to assign it to a variable. So using your examples:
MyFunction1(){
int answer;
int Value2 = 2;
answer = DoSomething(Value2);
}
If you could provide a more specific example of what you’re trying to do, perhaps I could provide more help, but hopefully this gets you started.
1
solved How to return data to a function? [closed]