Scala Logical Operators

Advertisements


The following simple example program demonstrates the logical operators operators. Copy and paste the following Java program in Test.scala file and compile and run this program:

object Test {
   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) );
   }
} 

This would produce the following result:

C:/>scalac Test.scala
C:/>scala Test
a && b = false
a || b = true
!(a && b) = true

C:/>


Advertisements
Advertisements