Presentation is loading. Please wait.

Presentation is loading. Please wait.

Midterm preview.

Similar presentations


Presentation on theme: "Midterm preview."— Presentation transcript:

1 Midterm preview

2 True / False statement: double int = 2.0;
The following is a syntactically correct variable declaration and assignment statement: True / False double int = 2.0;

3 The diagram in Figure 1a is the decision structure logic of the Java statements in Figure 1b.
if (Condition_1){ if (Condition_2){ Statement_B; }else{ Statement_C; } if (! Condition_1){ Statement_A; Figure 1a Figure 1b True / False

4 Java is a case sensitive programming language. True / False

5 True / False letter = “a”; statement is syntactically correct:
Assuming that letter has been declared as a variable of type char, the below statement is syntactically correct: True / False letter = “a”;

6 True / False True / False
For the logical AND operator, &&, which connects two boolean expressions, both expressions must be false for the overall expression to be false. True / False

7 The below two pieces of code output the same thing to the console:
True / False The below two pieces of code output the same thing to the console: int someVariable = 0; System.out.println(“Output : “ + someVariable); int someVar1 = 1, someVar2 = 2; System.out.println(“Output : “ + someVar1 / someVar2);

8 True / False Syntax errors are mistakes that the programmer has made that violate the rules of the programming language.

9 True / False The following Java code is syntactically incorrect:

10 True / False The following piece of Java code is syntactically correct:

11 True / False The equality operator, ==, cannot be used to compare the values stored in two variables of type String. You can compare the values of the variables, but not actual String values.

12 Assuming x has been declared as a variable of type int, the below Java code in the box is equivalent to which of the logical statements? A. If x is greater than 0 and x is less than 99 B. If x is greater than 1 and x is less than 99 C. If x is (0 or greater) and x is less than 99 D. If x is (0 or greater) and x is at most 99 if (x > -1 && x < 100) D.

13 A. String sentence = “heya”; if (x > -1 && x < 100)
What does the following piece of Java code output: A. heya B. Heya C. HeYa D. HEYA String sentence = “heya”; System.out.println(sentence.toLowerCase()); if (x > -1 && x < 100) A.

14 13. Major components of a typical modern computer consist of:
13. Major components of a typical modern computer consist of: A. The Central Processing Unit B. Input/output devices C. Secondary storage devices D. All of the above D.

15 int x = 25, y = 8; x += (7-y); y--; A.
What will be the values of x and y after the following code is executed? A. x = 24, y = 7 B. x = 24, y = 8 C. x = 25, y = 7 D. x = 25, y = 8 E. x = 26, y = 7 F. x = 26, y = 8 int x = 25, y = 8; x += (7-y); y--; if (x > -1 && x < 100) A.

16 double percentVal = 0.0; int purchase = 950; char cust = 'N';
What would be the value of percentVal after the following statements are executed? A. x = 24, y = 7 B. x = 24, y = 8 C. x = 25, y = 7 D. x = 25, y = 8 E. x = 26, y = 7 F. x = 26, y = 8 double percentVal = 0.0; int purchase = 950; char cust = 'N'; if (purchase > 1000){ if (cust == 'Y') percentVal = .05; else percentVal = .04; } else { percentVal = .03; percentVal = .02; } if (x > -1 && x < 100) A. 0.05 B. 0.04 C. 0.03 D. 0.02 E A.

17 Please plug this code in your jGrasp to catch all the errors…
For the below Java code, circle any portion that contains a syntax error. Circle those parts of the Java code where there is a mistyped character, missing semicolon, etc. A. x = 24, y = 7 B. x = 24, y = 8 C. x = 25, y = 7 D. x = 25, y = 8 E. x = 26, y = 7 F. x = 26, y = 8 public class HowMuchTimeRemaining public static void main (String[] args){ timeRemaining double = 12.5; timeSinceStart double = 33.0; if (timEremaining =< ){ System.out.println("Less than 10 minutes left.") } else if (timeRemaining < ){ System("Less than but more than minutes left.") } else { System.out.println("Ahh. At least 20 minutes remaining.") } } } if (x > -1 && x < 100) Please plug this code in your jGrasp to catch all the errors…

18

19 Explain the following line of code (do NOT predict the value of x; explain what the statement does).
final int x = 10/5; Your Answer : x is going to be equal 2, one can not change it’s value after this assignment because x is declared “final”.

20 What is the value of y after the following code is executed?
int y = 1; while (y < 10){ y += 3; } 10

21 What is the output of the following Java Program?
Your Answer : ________________________________________________ public class MidtermQuestion { public static void main (String[] args){ String cwu = "Central Washington University"; System.out.print(cwu.substring(0,1)); System.out.println(cwu.substring(cwu.length()-3 ,cwu.length())); } }

22 The binary encoding 00001110 is equivalent to what base-10 number
The binary encoding is equivalent to what base-10 number? Show your work to receive partial credit, in the case that your answer is incorrect. Your Answer : 14

23 Write a one-line syntactically correct Java statement that declares a variable animal of type String and assigns it the value tiger Your Answer: String animal = “tiger”;

24 for (int I = 2; I =< 50; I +=2;) { System.out.println(i); }
Write a Java program that will print to the console all even integers starting from 2 through (and including) 50. Complete the program, which has been started for you. Hint: you can use a while or for loop. Hint 2: One correct solution requires only 3 lines of VERY simple code. // A program that prints the even integers // from 2 through (and including) 50 public class EvenNumFrom2Through50 { // the main routine public static void main (String[] args) {   for (int I = 2; I =< 50; I +=2;) { System.out.println(i); } } }

25 Which of the following statements is/are true about comments.
A. A single line comment begins with the characters \\ B. A multiple-line comment begins with */ C. The following is a syntactically correct comment: // */ */ ////////// D. Single-line comments are ignored by the compiler E. Multiple-line comments are not ignored by the compiler F. Multiple-line comments must end with the characters /*

26 Based on the for-loop shown below, which of the lettered choice is/are correct?
A. The body of the for-loop will be executed 5 times B. The i+=2 part of the for loop will be performed 5 times C. The output produced by the for loop will be D. The i+=2 part of the for loop is performed as many times as the i<10 check is performed E. The i<10 part of the for loop is the initialization portion, and is executed only once F. The i+=2 part of the for loop is executed at least once. for (int i=-1; i<10; i+=2){ System.out.print(i); }


Download ppt "Midterm preview."

Similar presentations


Ads by Google