Download presentation
Presentation is loading. Please wait.
Published byEleanor Merryl Ellis Modified over 8 years ago
1
Midterm preview
2
double int = 2.0; True / FalseThe following is a syntactically correct variable declaration and assignment statement:
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 1aFigure 1b True / False
4
Java is a case sensitive programming language. True / False
5
letter = “a”; True / FalseAssuming that letter has been declared as a variable of type char, the below statement is syntactically correct:
6
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
int someVariable = 0; System.out.println(“Output : “ + someVariable); int someVar1 = 1, someVar2 = 2; System.out.println(“Output : “ + someVar1 / someVar2); The below two pieces of code output the same thing to the console:
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
if (x > -1 && x < 100) 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
13
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());
14
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
15
if (x > -1 && x < 100) 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--;
16
if (x > -1 && x < 100) 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 { if (cust == 'Y') percentVal =.03; else percentVal =.02; } percentVal =.05; A.0.05 B.0.04 C.0.03 D.0.02 E. 0.01
17
if (x > -1 && x < 100) 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 =< 10.647320){ System.out.println("Less than 10 minutes left.") } else if (timeRemaining < 20.2098756434){ System("Less than 20.2098756434 but more than 10.647320 minutes left.") } else { System.out.println("Ahh. At least 20 minutes remaining.") } } } Please plug this code in your jGrasp to catch all the errors…
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
int y = 1; while (y < 10){ y += 3; } What is the value of y after the following code is executed? 10
21
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())); } } What is the output of the following Java Program? Your Answer : ________________________________________________
22
The binary encoding 00001110 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
// 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); } } } 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.
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
for (int i=-1; i<10; i+=2){ System.out.print(i); } 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 -113579 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.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.