please in java programming Question 1 If you use a short-circuit operator to com
ID: 3915447 • Letter: P
Question
please in java programming Question 1 If you use a short-circuit operator to combine two expressions a. the first expression is evaluated only if it can affect the result b. the result of the expressions are reversed c. the second expression is evaluated only if it can affect the result d. both expressions are always evaluated 1 points Question 2 How many lines are printed on the console when the following for loops are executed? for (int i = 1; i < 5; i += 2) { for (int j = 0; j < i; j++) { System.out.println(j); } } a. 2 b. 5 c. 4 d. 20 1 points Question 3 Code example 4-1 int limit = 0; for (int i = 10; i >= limit; i -= 2) { for (int j = i; j <= 1; j++) { System.out.println("In inner for loop"); } System.out.println("In outer for loop"); } (Refer to code example 4-1.) How many times does “In outer for loop” print to the console? a. 11 b. 8 c. 10 d. 6 1 points Question 4 What is the value of routeNumber after the following statement is executed if the value of zipCode is 93705? switch (zipCode) { case 93705: case 93706: routeNumber = 1; break; case 93710: case 93720: routeNumber = 2; break; default: routeNumber = 0; break; } a. undefined b. 0 c. 2 d. 1 1 points Question 5 If number is 20, what is printed to the console after this code is executed? for (int i = 3; i <= number; i += 2) { if (number % i == 0) { System.out.println(i); if (i == number) { System.out.println("special"); } break; } } a. 5 special b. 20 special c. 5 d. 5 5 special e. 2 1 points Question 6 In a while loop, the Boolean expression is tested a. both before and after the loop is executed b. after the loop is executed c. before the loop is executed 1 points Question 7 Assume the user enters “X” at the first console prompt when the following code is executed. The value of numOfEntries will be String option = ""; int numOfEntries = 0; do { numOfEntries++; System.out.print("Enter 'C' to continue."); option = sc.next(); } while (choice.equalsIgnoreCase("C")); a. equal to one b. equal to zero c. greater than one 1 points Question 8 Code example 4-1 int limit = 0; for (int i = 10; i >= limit; i -= 2) { for (int j = i; j <= 1; j++) { System.out.println("In inner for loop"); } System.out.println("In outer for loop"); } (Refer to code example 4-1.) How many times does “In inner for loop” print to the console? a. 5 b. 7 c. 2 d. 0 e. 1 1 points Question 9 To combine two or more Boolean expressions into a single expression, you use ____________ operators. 1 points Question 10 How many lines are printed on the console when the following for loop is executed? for (int i = 2; i < 10; i++) { System.out.println(i); } a. 7 b. 9 c. 10 d. 8 1 points Question 11 Assume that the variable named entry has a starting value of 9 and number has a value of 3. What is the value of entry after the following statements are executed? if ((entry > 9) || (entry/number == 3)) { entry--; } else if (entry == 9) { entry++; } else { entry = 3; } a. 3 b. 10 c. 9 d. 8
Explanation / Answer
1) Answer is C. There are two cases of short-circuiting
a. false && exp2 - no need to evaluate exp2 i.e right-hand side as it is always false
b. true || exp2 -no need to evaluate exp2 i.e right-hand side as it is always true.
Hence, in both cases expression 2 is not evaluated when it is not affecting results.
2) Answer is c , output is
3) Answer is d
4) Answer is A,
routeNumber variable is not defined,if it is defined then value must be 1
5) Answer is c
Output is: 5
6) Answer is c,
while(expresion){ calculation; incrememnt}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.