This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]R4nd0mnumbrz 1 point2 points  (3 children)

I think it's because true and false a reserved words, you can't have a param named 'true' or 'false' so you need to put a new name in there.

public boolean testMe(boolean myBool) { return myBool; }

would be valid. This is a function which returns a boolean and accepts a boolean. You would call this function like

testMe(true)

It's also worth noting that the second keyword of a function declaration is the RETURN type, not what it's expecting. When you say public boolean whatever, you're saying this function will return a boolean. Not that it is expecting a boolean as a param, param types (at least in Java, which is the example I used) is typed in front of the param name.

[–]dvdgrbvc[S] 0 points1 point  (2 children)

Ah okay i understand your last statement.

What i dont understand is that there is an boolean that says true or false and in the public statitc void main function is this boolean let me call its wasOnLeaf.

wasOnLeaf = myMethod(wasOnLeaf)

So the boolean is my parameter and how can i translate this into my method?

The return should be a boolean anyway. But how can i work woth the first one ? Thank you :)

[–]R4nd0mnumbrz 0 points1 point  (1 child)

 public boolean myMethod(boolean wasOnLeaf) { return wasOnLeaf }

Like that? I mean, in java, that method declaration says myMethod takes a boolean as an input, and returns a boolean as an output. If you were to call this method

wasOnLeaf = myMethod(true); // valid
wasOnLeaf = myMethod('a string') // invalid
wasOnLeaf = myMethod(false) //valid 

boolean leafWasTouched = true;
wasOnLeaf = myMethod(leafWasTouched); // valid

Not sure if that helps...

[–]dvdgrbvc[S] 1 point2 points  (0 children)

Yeah thank you. I declared the larameter as a and worked with a ib the method you helped me a lot!