Skip to content

Latest commit

 

History

History
80 lines (63 loc) · 1.09 KB

File metadata and controls

80 lines (63 loc) · 1.09 KB

Logical Operators

Objectives

  1. What is the output of the following code:
package main

import "fmt"

func main() {
    x := 2017
    result1 := x > 50 && x < 2020
    result2 := x > 50 && x%2 == 0
    result3 := x%2 == 1 && x+3 == 2025
    fmt.Println(result1)
    fmt.Println(result2)
    fmt.Println(result3)

    x += 5
    result1 = x > 50 && x < 3000
    result2 = x > 50 && x < 3000
    result3 = x > 50 && x < 3000   
    fmt.Println(result1)
    fmt.Println(result2)
    fmt.Println(result3)
}
  1. What is the output of the following code:
package main

import "fmt"

func main() {
    x := 2017
    result1 := x > 50 || x < 2020
    result2 := x > 50 || x%2 == 0
    result3 := x%2 == 1 || x+3 == 2025
    fmt.Println(result1)
    fmt.Println(result2)
    fmt.Println(result3)

    x += 5
    result1 = x > 50 || x < 3000
    result2 = x > 50 || x < 3000
    result3 = x > 50 || x < 3000
    fmt.Println(result1)
    fmt.Println(result2)
    fmt.Println(result3)
}

Solution

  1. Output:
true
false
false
true
true
true
  1. Output:
true
true
true
true
true
true