mardi 30 juin 2020

How does if-statements work within a method in Java [closed]

!Very edited to provide more details!

When calling a method I want it to return either true or false. Because this is for a school assignment and it will go through an anti-plagarism program I cannot provide too much details on it, so I just show a simplified version of it.

I have a constructor and I have created two objects to it (not sure if it is correct described but hopefully you get what I mean). Say the constructor name is Flowers, and my objects are lily and rose.

In the main method it would sort of look like this.

Flowers lily = new Flowers(12);
Flowers rose = new Flowers(5);

rose.example(lily);

The example method:

public boolean example(Flowers name) {
    if (value == name.value) {
        return true;
    } else {
        return false;
    }   
}

If true I then want something to happen.

Aucun commentaire:

Enregistrer un commentaire