Jawaban Java Fudential Final Midterm [PDF]

  • 0 0 0
  • Suka dengan makalah ini dan mengunduhnya? Anda bisa menerbitkan file PDF Anda sendiri secara online secara gratis dalam beberapa menit saja! Sign Up
File loading please wait...
Citation preview

1.



What are Java's simple types? boolean, byte, char, double, float, int, long, and short (*) boolean, byte, string, thread, int, double, long and short object, byte, string, char, float, int, long and short boolean, thread, stringbuffer, char, int, float, long and short boolean, thread, char, double, float, int, long and short



2.



Which of the following are relational operators in Java?



(Choose all correct answers)



< (*) ,,,,= str2



Str1 -= str2;



Incorrect. Refer to Section 4 Lesson 4.



2. The following program prints "Not Equal". True or false? Review (1) Points True



False (*)



Mark for



Incorrect. Refer to Section 4 Lesson 4.



3. When a String object is created it must be assigned a value. True or false? Mark for Review (1) Points True



False (*)



Incorrect. Refer to Section 4 Lesson 4.



4. Which of the following creates a String reference named s and instantiates it? Mark for Review (1) Points (Choose all correct answers) String s=""; (*)



s="s";



String s;



String s=new String("s"); (*)



Incorrect. Refer to Section 4 Lesson 4.



5. What is printed by the following code segment?



Mark for Review (1) Points



\\\\



\\\\\\\ (*)



\\\\\\\\\\\\\\



\\



Correct 6. Which line of Java code Mark for Review properly calculates the area of a triangle using A=1/2(b)(h) where b and h are Java primitive integers? (1) Points double A=1/2*b*h;



double A=1/2bh;



double A=(double)1/(double)2*b*h; (*)



double A=(double)(1/2)*b*h; Incorrect. Refer to Section 4 Lesson 3.



7. What are Java's primitive types? Mark for Review (1) Points boolean, byte, char, double, float, int, long, and short (*)



boolean, byte, string, thread, int, double, long and short



object, byte, string, char, float, int, long and short



boolean, thread, stringbuffer, char, int, float, long and short



boolean, thread, char, double, float, int, long and short Incorrect. Refer to Section 4 Lesson 3.



8. Which of the following defines a driver class? Mark for Review (1) Points Contains a main method and other static methods. (*)



Contains classes that define objects.



Contains a main method, a package, static methods, and classes that define objects.



None of the above. Incorrect. Refer to Section 4 Lesson 2.



9. The following defines a package keyword: Mark for Review (1) Points Defines where this class lives relative to other classes, and provides a level of access control. (*) Provides the compiler information that identifies outside classes used within the current class. Precedes the name of the class. Incorrect. Refer to Section 4 Lesson 2.



10. A _______________ is used to organize Java related files.



Mark for Review (1) Points Project



Workspace



Package (*)



Collection Incorrect. Refer to Section 4 Lesson 1. 11. For every opening curly brace { there does not need to be a closing curly brace} for the program to compile without error. True or False? Mark for Review (1) Points True



False (*) Correct



12. You can return to the Eclipse Welcome Page by choosing Welcome from what menu? Mark for Review (1) Points File



Edit



Help (*)



Close Incorrect. Refer to Section 4 Lesson 1.



13. Four variables are required to support a conversion of one unit of measure to another unit



of measure. True or False? Mark for Review (1) Points True



False (*) Incorrect. Refer to Section 4 Lesson 1.



14. When converting gallons to liters its best to put the calculation result into a variable with a _______________ data type. Mark for Review (1) Points



int



double (*)



boolean



None of the above Correct



Section 5 (Answer all questions in this section)



15. How many times will the following loop be executed? What is the value of x after the loop has finished? What is the value of count after the loop has finished? int count = 17; int x = 1; while(count > x){ x*=3; count-=3; } Mark for Review (1) Points 4; 8; 27



3; 27; 8 (*)



5; 27; 8



5; 30; 5



3; 9; 11 Correct 16. Why are loops useful ? Mark for Review (1) Points They save programmers from having to rewrite code.



They allow for repeating code a variable number of times.



They allow for repeating code until a certain argument is met.



All of the above. (*)



Incorrect. Refer to Section 5 Lesson 2.



17. What should replace the comment "//your answer here" in the code below if the code is meant to take no action when i % 2 is 0 (in other words when i is even)? for(int i = 0; i < 10; i++){
if(i%2 == 0) //your answer here else k+=3; } Mark for Review (1) Points continue; (*)



break;



return;



k+=1;



Correct



18. Consider that a Scanner has been initialized such that: Scanner in = new Scanner(System.in); Which of the following lines of code reads in the user's input and sets it equal to a new String called input? Mark for Review (1) Points String input = in.next(); (*)



String input = in.close();



String input = new String in.next();



String input = in.nextInt();



Incorrect. Refer to Section 5 Lesson 1.



19. The following prints Yes on the screen. True or false? True



False (*)



Mark for Review (1) Points



Correct



20. The six relational operators in Java are: Mark for Review (1) Points >,,,,