Scala - Logical Operators


Advertisements


Try the following example program to understand all the logical operators available in Scala Programming Language.

Example

object Demo {
   def main(args: Array[String]) {
      var a = true;
      var b = false;

      println("a && b = " + (a&&b) );
      
      println("a || b = " + (a||b) );
      
      println("!(a && b) = " + !(a && b) );
   }
} 

Save the above program in Demo.scala. The following commands are used to compile and execute this program.

Command

\>scalac Demo.scala
\>scala Demo

Output

a && b = false
a || b = true
!(a && b) = true

scala_operators.htm

Advertisements