

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


This quiz is to be taken by yourself with closed books, closed notes, no calculators.
Operator Precedence Table Operators Associativity
1) Fully insert parentheses in the expressions below to show correct evaluation following the rules of precedence and associativity. What gets printed? (2 pt)
public class Q1_ { public static void main( String[] args ) { System.out.println( -1 + 2 * 6 + 14 / 4 ); _________
System.out.println( 6 + 7 - 2 % 11 + 3 ); _________ } }
2) What gets printed? (5 pts)
public class Q1_ { public static void main( String[] args ) { final int MAX = 2; int i = -2, j = -3;
for (i = 0; i < MAX; ++i ) { j = 1; while ( j <= MAX ) { System.out.println( i + " " + j ); ++j; } }
System.out.println( i + " " + j );
} // end main() }
3) What gets printed? (4 pts)
public class Q1_ { public static void main( String[] args ) { int i = 1, j = 2, k = 3, m = 2;
System.out.println( i >= 1 && j < 4 ); System.out.println( j >= i || k == m ); System.out.println( !( k > m ) ); System.out.println( !((i > 4) || (j <= 6)) == ((i <= 4) && (j > 6)) ); } }
4) Which line(s) [after line 6] would cause a compiler error and how would you fix that/those line(s) so it would compile correctly?
(4 pts)
1 public class Q1_4 { 2 public static void main( String[] args ) { Line number(s)__________________________ 3 int x; 4 long y; 5 double z; 6 7 x = 15; 8 z = 4.5; 9 y = z; 10 y = x; 11 x = y;
12 z = y; 13 } 14 }