Review for Test Lessons 9-12

Review for Test Lessons 9-12

<p>Name:______Date:______Block:______</p><p>Review for Test Lessons 9-12</p><p>1. Show the basic skeleton of an if - else structure.</p><p>2. In the following code, assume that the portion designated with <#1> is a true statement. What will be the output?</p><p> if( <#1> ) { System.out.print(“Elvis”); } System.out.println(“ Presley”);</p><p>3. In problem 2, what would be the output if <#1> was a false statement?</p><p>4. If you wanted to compare the contents of two Strings, s1 and s2, which of the following would be appropriate to use? a. s1.equals(s2) b. s2.equals(s1) c. s1.equalsIgnoreCase(s2) d. All of the above e. s1 = = s2 f. None of these</p><p>5. In a switch statement ( switch(???) ) what are two types of variables that may be used in the area designated by ???</p><p>6. What is the purpose of default in a switch structure?</p><p>Notice in the following code that there are some missing break commands. Use this code to answer problems 7 and 8.</p><p> int p = ??; int x = 79; switch(p) { case 1: x = 20; break; case 2: x = 2; case 3: x = 3; default: x ++; } 7. If p = 2 what is the final value of x?</p><p>8. If p = 1 what is the final value of x? For questions9 to 13, consider the following code:</p><p> int sum = 0; for(int j = 0; j < 3; j++) { sum = sum + 2; } System.out.println(sum);</p><p>9. Identify the control expression.</p><p>10. Identify the step expression.</p><p>11. Identify the initializing expression.</p><p>12. How many times does the loop iterate (repeat)?</p><p>13. What is printed?</p><p>14. Write code that forms the basic skeleton of a while loop.</p><p>15. Write code that forms the basic skeleton of a do-while loop</p><p>16. What is the effect of break when encountered in a loop?</p><p>17. What is the effect of continue when encountered in a loop?</p><p>18. What is the major difference in a while and a do-while loop?</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    2 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us