# Lesson 7 - Activity 2 - Can you use logical operators?

**URL:** <https://club.ministryoftesting.com/t/lesson-7-activity-2-can-you-use-logical-operators/31706>\
**Category:** Discussions\
**Tags:** java-intro\
**Created:** [28 November 2019 15:54 UTC](https://club.ministryoftesting.com/t/lesson-7-activity-2-can-you-use-logical-operators/31706 "2019-11-28T15:54:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mike\_talks](https://sea2.discourse-cdn.com/flex020/user_avatar/club.ministryoftesting.com/mike_talks/32/11115_2.png) [@mike\_talks](https://club.ministryoftesting.com/u/mike_talks)\
**Post date:** [28 November 2019 15:54 UTC](https://club.ministryoftesting.com/t/lesson-7-activity-2-can-you-use-logical-operators/31706/1 "2019-11-28T15:54:15Z")

</div>

**Time:** 15 minutes

**Purpose:** This activity helps you get familiar with using logical operators

**Introduction:** You’re had experience using relational operators, next step is logical operators and what they output

**Task:** Declare bool1, bool2, bool3 as Booleans.  
Set bool1 and bool2 to true, bool3 to false.

1. Print the value of bool1 AND bool2
2. Print the value of bool1 AND bool 3
3. Print the value of bool1 OR bool 2.
4. Print the value of bool1 OR bool 3.
5. Print the value of NOT bool1.
6. Print the value … generate an AND of bool1 and bool2. Process this result in an OR with bool3.

---

<div class="post-metadata">

**Author:** ![huib.schoots](https://sea2.discourse-cdn.com/flex020/user_avatar/club.ministryoftesting.com/huib.schoots/32/7014_2.png) [@huib.schoots](https://club.ministryoftesting.com/u/huib.schoots)\
**Post date:** [21 March 2020 17:25 UTC](https://club.ministryoftesting.com/t/lesson-7-activity-2-can-you-use-logical-operators/31706/2 "2020-03-21T17:25:10Z")

</div>

```
    boolean bool1, bool2, bool3;
    bool1 = bool2 = Boolean.TRUE;
    bool3 = Boolean.FALSE;

    System.out.println(newLine + "Given: " + newLine + "bool1 = " + bool1 + newLine +
            "bool2 = " + bool2 + newLine + "bool3 = " + bool3);

    booleanResult = (bool1 && bool2);
    System.out.println("Then bool1 && bool2 is: " + booleanResult);

    booleanResult = (bool1 && bool3);
    System.out.println("Then bool1 && bool3 is: " + booleanResult);

    booleanResult = (bool1 || bool2);
    System.out.println("Then bool1 || bool2 is: " + booleanResult);

    booleanResult = (bool1 || bool3);
    System.out.println("Then bool1 || bool3 is: " + booleanResult);

    booleanResult = (!bool1);
    System.out.println("Then !bool1 is: " + booleanResult);

    booleanResult = ((bool1 && bool2)||(bool3));
    System.out.println("(bool1 && bool2)||(bool3) is: " + booleanResult);
```

---

<div class="post-metadata">

**Author:** ![mike\_talks](https://sea2.discourse-cdn.com/flex020/user_avatar/club.ministryoftesting.com/mike_talks/32/11115_2.png) [@mike\_talks](https://club.ministryoftesting.com/u/mike_talks)\
**Post date:** [30 March 2020 03:27 UTC](https://club.ministryoftesting.com/t/lesson-7-activity-2-can-you-use-logical-operators/31706/3 "2020-03-30T03:27:31Z")

</div>

Good work, esp with combining multiple operations at the end.
