Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solution Hw-1.2 #172

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/main/java/core/basesyntax/BooleanExpression.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package core.basesyntax;

import java.util.List;

public class BooleanExpression {

/**
Expand All @@ -14,6 +16,12 @@ public class BooleanExpression {
* без использования конструкций if-else</p>
*/
public boolean booleanExpression(boolean a, boolean b, boolean c, boolean d) {
return false;
int countTrue = 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a bit too complicated, try to solve it using just logic operators &&, ||, ^ (XOR)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

int countFalse = 0;
for (Boolean bool : List.of(a, b, c, d)) {
countTrue = bool.toString().equalsIgnoreCase("true") ? countTrue + 1 : countTrue;
countFalse = bool.toString().equalsIgnoreCase("false") ? countFalse + 1 : countFalse;
}
return (countTrue | countFalse) == 2;
}
}