|
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);
Question 2. Please type your answer here: ____________________int x, y; x = 2; y = 3; y = x; System.out.println(x + " versus " + y);
Question 3. int x, y;
x = 2; y = 3;
System.out.println("1" + x + y);
Please type your answer here: ____________________
Question 4. int x, y;
x = 2; y = 3;
System.out.println("1" + (x + y));
Please type your answer here: ____________________
Question 5.
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');
Question 6. Please type your answer here: ____________________5 * (7 + 4 / 2)
(Please use the Java keyword for the type).
Question 7. Please type your answer here: ____________________i != 3
(Please use the Java keyword for the type.
Also, assume i is a double).
Question 8.
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);
Question 9.
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);
Question 10.
Please type your answer here: ____________________int a; a = 'C' - 'A'; System.out.println(a);
Question 11. 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.
Question 12. 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); }
Please type your answer here: ____________________ Note that curly braces have been added to the code from the previous exercise, and the same comment about indentation applies.
Question 13. int x = 3;
if (x > 5)
if (x < 10)
System.out.print(1);
else
System.out.print(2);
System.out.print(3);
Please type your answer here: ____________________ Note that the program may or may not be indented correctly so think about it carefully.
Question 14. int x = 3;
if (x > 5) {
if (x < 10)
System.out.print(1); }
else
System.out.print(2);
System.out.print(3);
Please type your answer here: ____________________ Note that curly braces have been added to the code from the previous exercise, and the same comment about indentation applies.
Question 15. 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);
Please type your answer here: ____________________ Note that the program may or may not be indented correctly so think about it carefully.
Question 16. 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.
Question 17. 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.
Question 18. 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.
Question 19. 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