Monday, March 26, 2018

Precedence of Java code

/* Example of Precedence */
package Precedence;
public class Precedence
{
    public static void main(String[] args)
    {
        int a = 5, b = 10, c = 15, d = 20;
        int x, y, z;
        x = a * b - c;
        y = a - d / b + c;
        prln("a = " +a+ "\tb = "+b);    // Implies(5 * 10) - 15, Not 5 * (10 - 15)
        prln("c = " +c+ "\td = "+d);    // Implies 5 - (20 / 10) + 15
        prln("a * b - c = "+x);
        prln("a - d / b + c = "+y);
    }
    static void prln(Object anyObject)
    {
        System.out.println(anyObject);
    }
    static void pr(Object anyObject)
    {
        System.out.print(anyObject);
    }
   
}









Share:

0 comments:

Post a Comment

Blogger templates