Java Reference
In-Depth Information
Review Questions
1. What is the result of the following code?
3. int x = 10, y = 3;
4. if(x % y == 2)
5. System.out.print(“two”);
6. System.out.print(x%y);
7. if(x%y == 1)
8. System.out.print(“one”);
A. two
B. two1
C. two2
D. one
E. 1one
2. What is the result of the following code?
4. int x = 5, y = 10;
5. boolean b = x < 0;
6. if(b = true) {
7. System.out.print(x);
8. } else {
9. System.out.print(y);
10. }
A. Compiler error on line 5.
B. Compiler error on line 6.
C. 5
D. 10
E. The code compiles but there is no output.
3. What is the output of the following program?
1. public class Question3 {
2. public static void main(String [] args) {
3. String year = “Senior”;
4. switch(year) {
5. case “Freshman” :
6. case “Sophomore” :
7. case “Junior” :
8. System.out.print(“See you next year”);
9. break;
10. case “Senior” :
Search WWH ::




Custom Search