Expressions and If Statements Worksheet

 

  1. Given the following algebraic expressions, convert each to the equivalent correct Java expression.
         a.  b - 4ac
    
         b.  x(y + z)
    
         c.       1
             ------------
             x  +  x  * 3
    
         d.  a  +  b
             -------
             c  -  d
    
  2. What is the output of each of the following statements? Assume the following declarations: int a=10, b=5, c=8, temp=0;
         1.  if (a <= b)
                b = a;
             System.out.println(a + "  " + b);
    
         2.  if (a <= b) {
                b = a;
                System.out.println(a + "  " + b);
             }
    
         3.  if (a > b)
                temp = a;
             a = b;
             b = temp;
             System.out.println(a + " " + b);
    
         4.  if (a > b) {
                temp = a;
                a = b;
                b = temp;
                System.out.println(a + "  " + b);
             }
    


Email Me | Office Hours | My Home Page | Department Home | MCC Home Page

© Copyright Emmi Schatz 2013