-1

I am writing an interface for the logic gates. I have the following code:

Then for the and gate I coded:

public class And 
{
    public boolean ope(
    {
        assert();

   }
}

Is there any way that I can change this to avoid assert and remove the ellipsis?

user3126119
  • 323
  • 1
  • 3
  • 10

1 Answers1

2

You could write the method so it accepts an arbitrary number of booleans. If any of the booleans is false, return false; otherwise, return true.

public boolean ope(boolean...list)
{
    for (boolean value: list) {
        if (!value) {
            return false;
        }
    }

    return true;
}

Note that this would return true for an empty list. That may or may not be what you want.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578