Friday, 13 November 2015

Java Tutorial : Java Operator Precedence Example


Click here to watch in Youtube : 
https://www.youtube.com/watch?v=HqhgMJn9hNM&list=UUhwKlOVR041tngjerWxVccw

PrecedenceOfOperator.java
class PrecedenceOfOperator
{
    public static void main(String[] args)
    {

        /*
         * Here x is assigned 13, not 20 because operator * has higher
         * precedence than +, so it first gets multiplied with 3*2 and then adds
         * into 7.
         */
        int x = 7 + 3 * 2;

        System.out.println("x : " + x);

        /*
         * Here is () is higher precedence than * so first 7+3=10 calculation
         * will be done, then 10 will be multiplied by 2 and the result is 20
         */

        int y = (7 + 3) * 2;

        System.out.println("y : " + y);

    }
}
Output
x : 13
y : 20
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/OperatorsDemoPrecedenceApp.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/OperatorsDemoPrecedenceApp

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/e1afee1d6e12479b500465256b2025d133889626/BasicJava/OperatorsDemoPrecedenceApp/?at=master

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge