In: Computer Science
no need to explain
11. What is output by the following code segment? boolean isHighTemp = true; double degree = 100.01; if (isHighTemp) if(degree >= 110) System.out.print(“Extremely Hot”); else System.out.println(“Not Hot”); A) Extremely Hot B) Not Hot C) Hot D) Extremely Hot Not Hot
12. To produce the output 2 4 6 8 10, what is the loop condition for the following loop? int n = 0; Page 3 do { n = n + 2; System.out.print(n + “ ”); }while (???) A) n < 10 B) n = 2
13. In Java, the value of the expression 23 % 6 is: A) 5 B) 2 C) 3 D) 4
14. Given the constant declaration final int CAPACITY = 10; which of the following is NOT a valid use of CAPACITY? A) CAPACITY += CAPACITY; B) CAPACITY = 100; C) int currentSize = CAPACITY + 9; D) A and B above
15. Given the following declaration and the method header for the Max method double x, y, z; Page 4 double Max(double, double); which of the following shows a syntactically invalid call to Max method: A) z = Max(x, y); B) z = Max((x+y+z); C) System.out.print(Max(x, (y+x) )); D) z = y + Max((y-x), (x+y));
11.
Answer: Not Hot(B)
here we declared degree=100.01
if(degree>=110) which is false 100.01<110
so else statement will be executed which is Not Hot
12.
Answer:A(n<10)
In the while loop we have to write the condition
which is n<10
if we write n=2
which is not a condition then it will became a infinet do while loop
so the answer is n<10
13.
Answer :(A) 5
% operator return the remonder of the division
here we use 23%6 the reminder when we divide 23/6 is 5
so the answer is 5
14.
Answer:(D) A and B above
because when you declare a variable with final keyword then
you cannot assign any value to it
but in option A we write CAPACITY+=CAPACITY here we are assigning the value to the final variable
which cannot be done
in option B we write CAPACITY=100 here also we are assigning the value to final variable
which cannot be done
so the answer is boath a and b
15.
Answer:(B)
z = Max((x+y+z);
Here we have to pass 2 parameter to the MAX function
and we are missing a closing )
so option is B is syntactically invalid