Java - What is the output: find the result of each expression

Question

What is the output of the following code.

public class Main
{
    public static void main(String[] args)
    {
        int a = 3, b = 10, c = 7;
        double w = 12.9, y = 3.2;
        
        int resultA = a + b * c;
        System.out.println("a + b * c = " + resultA);
        
        int resultB = a - b - c;
        System.out.println("a - b - c = " + resultB);
        
        int resultC = a / b;
        System.out.println("a / b = " + resultC);
        
        int resultD = b / a;
        System.out.println("b / a = " + resultD);
        
        int resultE = a - b / c;
        System.out.println("a - b / c = " + resultE);
        
        double resultF = w / y;
        System.out.println("w / y = " + resultF);
        
        double resultG = y / w;
        System.out.println("y / w = " + resultG);
        
        double resultH = a + w / b;
        System.out.println("a + w / b = " + resultH);
        
        double resultI = a % b / y;
        System.out.println("a % b / y = " + resultI);
        
        int resultJ = b % a;
        System.out.println("b % a = " + resultJ);
        
        double resultK = w % y;
        System.out.println("w % y = " + resultK);
    }
}


Click to view the answer

a + b * c = 73
a - b - c = -14
a / b = 0
b / a = 3
a - b / c = 2
w / y = 4.03125
y / w = 0.24806201550387597
a + w / b = 4.29
a % b / y = 0.9375
b % a = 1
w % y = 0.09999999999999964

Demo

public class Main
{
    public static void main(String[] args)
    {//w w w  .  j a va 2 s  .  c  o  m
        int a = 3, b = 10, c = 7;
        double w = 12.9, y = 3.2;
        
        int resultA = a + b * c;
        System.out.println("a + b * c = " + resultA);
        
        int resultB = a - b - c;
        System.out.println("a - b - c = " + resultB);
        
        int resultC = a / b;
        System.out.println("a / b = " + resultC);
        
        int resultD = b / a;
        System.out.println("b / a = " + resultD);
        
        int resultE = a - b / c;
        System.out.println("a - b / c = " + resultE);
        
        double resultF = w / y;
        System.out.println("w / y = " + resultF);
        
        double resultG = y / w;
        System.out.println("y / w = " + resultG);
        
        double resultH = a + w / b;
        System.out.println("a + w / b = " + resultH);
        
        double resultI = a % b / y;
        System.out.println("a % b / y = " + resultI);
        
        int resultJ = b % a;
        System.out.println("b % a = " + resultJ);
        
        double resultK = w % y;
        System.out.println("w % y = " + resultK);
    }
}

Related Quiz