Operators Precedence in Scala Last Updated : 25 Jun, 2019 Comments Improve Suggest changes Like Article Like Report An operator is a symbol that represents an operation to be performed with one or more operand. Operators are the foundation of any programming language. Which operator is performed first in an expression with more than one operators with different precedence is determined by operator precedence. For example, 10 + 20 * 30 is calculated as 10 + (20 * 30) and not as (10 + 20) * 30. when two operators of the same precedence appear in expression associativity is used. Associativity can be Right to Left or Left to Right. For example ‘*’ and ‘/’ have the same precedence and their associativity is Left to Right, so the expression “100 / 10 * 10” is worked as “(100 / 10) * 10”. In below table operators with the highest precedence appear at the top of the table and operators with the lowest precedence appear at the bottom. Operator Category Associativity ()[] Postfix Left to Right ! ~ Unary Right to Left * / % Multiplicative Left to Right + - Additive Left to Right >> >>> << Shift Left to Right < <= > >= Relational Left to Right == != Relational is equal to/is not equal to Left to Right == != Equality Left to Right & Bitwise AND Left to Right ^ Bitwise exclusive OR Left to Right | Bitwise inclusive OR Left to Right && Logical AND Left to Right | | Logical OR Left to Right = += -= *= /= %= >>= <<= &= ^= |= Assignment Right to left , Comma (separate expressions) Left to Right Below is the example of operator Precedence. Example : Scala // Scala program to show Operators Precedence // Creating object object gfg { // Main method def main(args: Array[String]) { var a:Int = 20; var b:Int = 10; var c:Int = 15; var d:Int = 5; var e = 0 // operators with the highest precedence // will operate first e = a + b * c / d; /* step 1: 20 + (10 * 15) /5 step 2: 20 + (150 /5) step 3:(20 + 30)*/ println("Value of a + b * c / d is : " + e ) } } Output: Value of a + b * c / d is : 50 In above example e = a + b * c / d; here, e is assigned 50, not 120 because operator * has a higher precedence than / than +, so it first gets multiplied with 10 * 15, then divide by 5 and then add into 20. Comment More infoAdvertise with us Next Article Operators Precedence in Scala D DivyaPareek Follow Improve Article Tags : Python Scala Scala-Operator Practice Tags : python Similar Reads Operators in Scala An operator is a symbol that represents an operation to be performed with one or more operand. Operators are the foundation of any programming language. Operators allow us to perform different kinds of operations on operands. There are different types of operators used in Scala as follows: Arithmeti 11 min read Scala Parser Combinators When a parser generator is required, some famous parsers that cross our mind are: Yacc and Bison for parsers written in C and ANTLR for parsers written in Java but they are designed to run for specific programming languages. This shortens the scope of use of parsers. However, Scala provides a unique 3 min read Parameterless Method in Scala Prerequisites - Scala | Functions A parameterless method is a function that does not take parameters, defined by the absence of any empty parenthesis. Invocation of a paramaterless function should be done without parenthesis. This enables the change of def to val without any change in the client cod 2 min read Scala | Reduce, fold or scan In this tutorial we will learn about Reduce, Fold and Scan functions in Scala. Reduce : Reduce function is applied on collection data structure in scala that contains lists, sets, maps, sequence and tuples. Parameter in the reduce function is a binary operation which merges all the elements from the 5 min read Scala Iterator find() method with example The find() method belong to the concrete value members of the class AbstractIterator. It is defined in the class IterableOnceOps. It finds the first element of the stated collection which satisfies the given predicate. It would not terminate for the infinite sized collections. Method Definition : de 1 min read Like