Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI 160 Midterm Review Rasanjalee DM. Multiple Choice Questions.

Similar presentations


Presentation on theme: "CSCI 160 Midterm Review Rasanjalee DM. Multiple Choice Questions."— Presentation transcript:

1 CSCI 160 Midterm Review Rasanjalee DM

2 Multiple Choice Questions

3 Question The Java compiler translates Java programs into machine language programs. TRUE FALSE

4 Answer The Java compiler translates Java programs into machine language programs. [FALSE]

5 Question System.out is an example of a method. TRUE FALSE

6 Answer System.out is an example of a method. TRUE FALSE [FALSE]

7 Question ice-cream is an illegal identifier in Java. TRUE FALSE

8 Answer ice-cream is an illegal identifier in Java. TRUE FALSE [TRUE]

9 Question Constructors have return type void. TRUE FALSE

10 Answer Constructors have return type void. TRUE FALSE [FALSE]

11 Fill in the Blanks

12 Questions Every variable in Java must be __________ before it is used. Single quotes are used with constants of the __________ type.

13 Answers Every variable in Java must be __________ before it is used. [declared] 2. Single quotes are used with constants of the __________ type. [char]

14 Questions A(n) __________ is used for signaling the end of the input. A(n) __________ is an action that an object can take and is specified in the class definition. Compiling a file called Game.java will produce a file called __________.

15 Answers A(n) __________ is used for signaling the end of the input. [sentinel value] A(n) __________ is an action that an object can take and is specified in the class definition. [method] Compiling a file called Game.java will produce a file called __________. [Game.class]

16 Question A(n) __________ is a data item that belongs to an object. __________ is the word used to say that there are no restrictions on the use of a method or data item can be used. The reserved word __________ can be used as a name for the calling the current object.

17 Answer A(n) __________ is a data item that belongs to an object. [instance variable] 4. __________ is the word used to say that there are no restrictions on the use of a method or data item can be used. [public] 5. The reserved word __________ can be used as a name for the calling object. [this]

18 Short Answer Questions

19 Question Add parentheses to the following expressions to indicate how Java will interpret them. (a) a * b * c - d / e (b) a + - b * c - d

20 Answer (a) ((a * b) * c) - (d / e) (b) (a + ((-b) * c)) - d

21 Question After the following statements have been executed, how many Fraction objects will exist, not counting garbage objects? Fraction f1 = new Fraction(1, 2); Fraction f2 = new Fraction(3, 5); Fraction f3 = f2;f2 = null;f1 = f2;

22 Answer One

23 Question Answer the questions below about this class. a)What are the names of the instance variables declared in this class? b)What are the signatures of the constructors declared in this class? c)What are the names of the parameters declared in this class? d)What are the signatures of the methods declared in this class? e)What are the names of the constants declared in this class?

24 Answer Answer the questions below about this class. a)What are the names of the instance variables declared in this class? name, slalomPoints, giantSlalomPoints, superGPoints, ussaNumber b)What are the signatures of the constructors declared in this class? public Skier (String name, String ussaNumber) c)What are the names of the parameters declared in this class? name, ussaNumber d)What are the signatures of the methods declared in this class? public String getBestEvent() e)What are the names of the constants declared in this class? MAXIMUM_POINTS

25 Code Analysis

26 Question What does the following program print? int[] arr = {1, 1, 0, 0, 0}; for (int i = 2; i < arr.length; i++) arr[i] = arr[i-1] + arr[i-2];

27 Answer What does the following program print? index = int[] arr = {1, 1, 0, 0, 0}; for (int i = 2; i < arr.length; i++) arr[i] = arr[i-1] + arr[i-2]; iarr[i-1]arr[i-2] arr[i]arr = = =

28 Question Show the EXACT output the following programs generate: public class e21 { public static void main (String args[]) { int num = 4; printNumbers(num); } private static void printNumbers(int n) { for (int i=1; i <= n; i++) { for (int k=1; k <= 2*(i-1)+1; k++) System.out.print(i); System.out.println(); }

29 Answer

30 Write Java Code

31 Question Write one line java statement declaring and creating a 1-d double array that stores whether or not precipitation was recorded on each day of one (non-leap year)

32 Answer boolean[] precipRecord = new boolean[365];

33 Question Write a one-line java statement declaring and creating a 2-d array named matrix with 24 rows and 80 columns.

34 Answer double[][] matrix = new double[24][80];

35 Question Write 1 or more java statements to display all the elements of the last column of the 2-d array matrix from the previous part

36 Answer for(int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/3360040/12/slides/slide_35.jpg", "name": "Answer for(int i=0; i

37 Question Write 1 or more java statements to compute and print the product of all the elements in the second row of the 2-d array matrix

38 Answer double product = 1 for(int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/3360040/12/slides/slide_37.jpg", "name": "Answer double product = 1 for(int i=0; i

39 Question Write 1 or more java statements to compute and print the number of upper case characters in a saying (stored in variable saying)

40 Answer int upper= 0; for(int i=0;i=‘A’ && saying.charAt(i)<=‘Z’) { upper+; } System.out.println(upper);

41 Question Write a method named toBinary that accepts an integer as a parameter and returns a string of that number's representation in binary. For example, the call of toBinary(42) should return "101010". We will assume a positive parameter.

42 Answer private static String toBinary(int num) { if (num == 0) return "0"; String str=""; while (num != 0) { str = (num%2)+str; num /= 2; } return str; }

43


Download ppt "CSCI 160 Midterm Review Rasanjalee DM. Multiple Choice Questions."

Similar presentations


Ads by Google