Spring Semester 2005

Here are some questions for you to work on for next time:
Question 1.
What is the output produced by the following
three lines (when correctly embedded in a complete program)?
Please type your answer here: ____________________int x, y; x = 2; y = 3; y = x; System.out.println(x + y);
Please type your answer here: ____________________int x, y; x = 2; y = 3; y = x; System.out.println(x + " versus " + y);
Please type your answer here: ____________________int x, y; x = 2; y = 3; System.out.println("1" + x + y);
Please type your answer here: ____________________int x, y; x = 2; y = 3; System.out.println("1" + (x + y));
Please note that the variables are of type char
.
Please type your answer here: ____________________char a, b, c; a = 'B'; b = 'C'; c = a; System.out.println(a + c + 'C');
Please type your answer here: ____________________5 * (7 + 4 / 2)
(Please use the Java keyword for the type).
Please type your answer here: ____________________i != 3
(Please use the Java keyword for the type.
Also, assume i
is a double
).
Please note that the variables are of type int
.
Please type your answer here: ____________________int a, b; a = 12; b = 5; System.out.println(a / b);
Please note that the variables are of type int
.
Please type your answer here: ____________________int a, b; a = 12; b = 5; System.out.println(a % b);
Please type your answer here: ____________________int a; a = 'C'  'A'; System.out.println(a);
Please type your answer here: ____________________int x = 3; if (2 > x) System.out.print(1); else System.out.print(2); if (x < 2) System.out.println(3); System.out.print(4);
Note that the program may or may not be indented correctly so think about it carefully.
Please type your answer here: ____________________int x = 3; if (2 > x) System.out.print(1); else System.out.print(2); if (x < 2) { System.out.println(3); System.out.print(4); }
Note that curly braces have been added to the code from the previous exercise, and the same comment about indentation applies.
Please type your answer here: ____________________int x = 3; if (x > 5) if (x < 10) System.out.print(1); else System.out.print(2); System.out.print(3);
Note that the program may or may not be indented correctly so think about it carefully.
Please type your answer here: ____________________int x = 3; if (x > 5) { if (x < 10) System.out.print(1); } else System.out.print(2); System.out.print(3);
Note that curly braces have been added to the code from the previous exercise, and the same comment about indentation applies.
Please type your answer here: ____________________if (2 <= 3) if (0 != 1) System.out.print(0); else System.out.print(1); System.out.print(2); if (2 > 3) if (0 == 1) System.out.print(3); else System.out.print(4); System.out.print(5);
Note that the program may or may not be indented correctly so think about it carefully.
Please type your answer here: ____________________boolean x; if (true) System.out.print(0); else System.out.print(1); x = (1 < 2) && (4 < 3); if (x) System.out.print(2); else System.out.print(3);
Note that the program may or may not be indented correctly so think about it carefully.
Please type your answer here: ____________________boolean x; if (true) System.out.print(3); else System.out.print(2); x = (1 < 2)  (4 < 3); if (x) System.out.print(1); else System.out.print(0);
Note that the program may or may not be indented correctly so think about it carefully.
else
keyword has been erased:
What is the program going to output when embedded in a complete program?boolean x; if (true) System.out.print(3); else System.out.print(2); x = (1 < 2)  (4 < 3); if (x) System.out.print(1);elseSystem.out.print(0);
Please type your answer here: ____________________
Note that the program may or may not be indented correctly now so think about it carefully.
else
keywords have been erased:
What is the program going to output when embedded in a complete program?boolean x; if (true) System.out.print(3);elseSystem.out.print(2); x = (1 < 2)  (4 < 3); if (x) System.out.print(1);elseSystem.out.print(0);
Please type your answer here: ____________________
Note that the program may or may not be indented correctly now so think about it carefully.
For next time try to solve these problems and be ready to discuss the answers.
Tue Jan 25 10:09:28 EST 2005