Test 2 CSCI 130 Summer 2010


  1. (3 points) Give the syntax for the if - else statement.
  2. (3 points) Give the flow of control for the if - else statement.
  3. (4 points) Write a code segment which prints the word even if the integer variable myNumber contains an even number and the word odd if the variable contains an odd number.
  4. (3 points) Give the syntax for the constructed if - else if - elsestatement.
  5. (4 points) Write a code segment which prints positive if the integer variable myNumber is positive, negative if the value is negative and zero if the value is zero.
  6. (3 points) Describe the switch statement.
  7. (4 points) Write a code segment which given an integer digit which contains a number between 0 and 9, prints out the name of the number. For example, if digit = 3 the word three should be printed.
  8. (3 points) Give the syntax for the while statement.
  9. (3 points) Describe the flow of control for the while statement.
  10. (4 points) Write a code segment which will print the first 100 multiples of three. (3,9,12, ...)
  11. (3 points) Give the syntax for the do-while statement.
  12. (3 points) Give the syntax for the for statement.
  13. (10 points) The file Data contains a set of numeric data, all floating point numbers. Write a code segment which will find the average of the data in the file.