Course Hero Logo

D zero or more times at the beginning of each

Course Hero uses AI to attempt to automatically extract content from documents to surface to you and others so you can study better, e.g., in search results, to enrich docs, and more. This preview shows page 22 - 27 out of 32 pages.

d. Zero or more times, at the beginning of each iteration.e. Zero or more times, at the end of each iteration.The correct answer is: At least once, at the beginning of each iteration.FeedbackYour answer is incorrect.See Section 3.4.1 of Eck (2014).
QuestionCorrectMark 1.00 out of 1.00Flag questionQuestion textConsider the following block of Java code. How many times will it output "Hello"?for (int i = 1; i < 10; i++){System.out.println("Hello");}Select one:3
FeedbackYour answer is correct.Notice that the condition is "i < 10", not "i <= 10". See Section 3.4.1 of Eck (2014).
QuestionCorrectMark 1.00 out of 1.00Flag questionQuestion textAssume "test" is a boolean variable. Which of the following expressions is equivalent to"test == true"?Select one:4FeedbackYour answer is correct.See Section 3.3.2 of Eck (2014).
QuestionCorrectMark 1.00 out of 1.00Flag questionQuestion textConsider the following block of Java code. How many times will it output "Hello"?for (int i = 1; i > 10; i++) ;{System.out.println("Hello");}Select one:5
FeedbackYour answer is correct.Notice the extra ";" at the end of the for loop. The loop iterates 9 times, but it does not outputanything. Then the separate code block runs once and outputs "Hello". See Sections 3.1.1 and 3.4.1of Eck (2014).The correct answer is: 1QuestionCorrectMark 1.00 out of 1.00Flag questionQuestion textWhat is output by the following Java program?class Compute {static int compute() { return 42; }static int compute(int i) { return i+1; }public static void main(String[] args) {System.out.println(compute(compute()));}}Select one:1a. 0b. 1c. 2d. 42e. 43
FeedbackYour answer is correct.The inner call to "compute()" has no argument, so it uses the first definition of the method, whichreturns the value 42. This 42 becomes the argument to the outer call. Because that call does havean argument, it uses the second definition of "compute". This method then returns 42+1, or 43. SeeSection 4.3.3 of Eck (2014).The correct answer is: 43
QuestionCorrectMark 1.00 out of 1.00Flag questionQuestion textWhat is output by the following Java program?class Zap {static boolean zap() { return true; }static int zap(boolean x) { return 0; }static double zap(int x) { return 0.5; }static String zap(double x) { return "Zap!"; }static boolean zap(String x) { return false; }public static void main(String[] args) {System.out.println(zap(zap(zap(zap()))));}}Select one:2
argument, so it uses the fourth method definition, which returns the String "Zap!" See Section 4.3.3of Eck (2014).

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 32 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Winter
Professor
N/A
Tags
Object Oriented Programming, Subroutine, public static void

Newly uploaded documents

Show More

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture