State Clearly All of Your Assumptions

State Clearly All of Your Assumptions

<p>Name :...... Comp 240 Quiz Written 2 ID # :...... Mar 17, 2005 1/3 State clearly all of your assumptions. Q1 (49) Q2 (21) Q3(30) Sum Good luck.</p><p>1 (49 pt) In the following questions, check all that apply. </p><p>1.a. What is the difference between a float and a double?  double variables store integers and float variables store floating-point numbers.  double variables store numbers with smaller magnitude and coarser detail.  double variables store numbers with larger magnitude and finer detail.</p><p>1.b. What is the default initial value of a String?  ""  "default"  default  null</p><p>1.c. In an expression containing values of the types int and double, the ______values are ______to ______values for use in the expression.  int, promoted, double.  int, demoted, double.  double, promoted, int.  double, demoted, int.</p><p>1.d. What does the expression x %= 10 do?  Adds 10 to the value of x, and stores the result in x.  Divides x by 10 and stores the remainder in x.  Divides x by 10 and stores the integer result in x.</p><p>1.e. Which of the following will count down from 10 to 1 correctly?  for ( int j = 10; j <= 1; j++ )  for ( int j = 1; j <= 10; j++ )  for ( int j = 10; j <= 1; j-- )  for ( int j = 10; j > 1; j-- )  for ( int j = 10; j >= 1; j-- ) Name :...... Comp 240 Quiz Written 2 ID # :...... Mar 17, 2005 2/3 1.f. Which of the following statements about the break statement is false?  The break statement is used to exit a repetition structure early and continue execution after the loop.  The break statement, when executed in a while, for or do…while, skips the remaining statements in the loop body and proceeds with the next iteration of the loop.  Common uses of the break statement are to escape early from a loop or to skip the remainder of a switch.</p><p>1.g. Suppose variable gender is MALE and age equals 60, how is the expression</p><p>( gender == FEMALE ) && ( age >= 65 ) evaluated?  The condition ( gender == FEMALE ) is evaluated first and the evaluation stops immediately.  The condition ( age >= 65 ) is evaluated first and the evaluation stops immediately.  Both conditions are evaluated, from left to right.  Both conditions are evaluated, from right to left.</p><p>Q2. (21 pt) What is the output of the code segment below for varying values of q?</p><p> switch( q ) { case 1: System.out.println( "apple" ); break; case 2: System.out.println( "orange" ); break; case 3: System.out.println( "banana" ); break; case 4: System.out.println( "pear" ); case 5: System.out.println( "grapes" ); default: System.out.println( "kiwi" ); }</p><p> q 0 1 2 3 4 5 6</p><p> kiwi apple orange banana pear grapes kiwi grapes kiwi kiwi Output Name :...... Comp 240 Quiz Written 2 ID # :...... Mar 17, 2005 3/3</p><p>Q3. (30 pt) What it the output of the following program?</p><p> public class Printing {</p><p> public static void main(String[] args) {</p><p> for ( int i = 1; i <= 5; i++ ) { for ( int j = 1; j <= i; j++ ) System.out.print( '*' );</p><p>System.out.println(); } // end of outer for } // end of method main</p><p>} // end of class Printing</p><p>* ** *** **** *****</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    3 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