1 / 21

CSC 204 Drill and Practice

CSC 204 Drill and Practice. Expressions, Types, Variables, Random Numbers. Declare a variable. Declare a variable named temperature capable of holding an integral value. Declare and initialize a variable. Declare a variable named temperature capable of holding an integral value.

lawson
Download Presentation

CSC 204 Drill and Practice

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSC 204 Drill and Practice Expressions, Types, Variables, Random Numbers

  2. Declare a variable • Declare a variable named temperature capable of holding an integral value.

  3. Declare and initialize a variable • Declare a variable named temperature capable of holding an integral value. • Give it the initial value 32.

  4. Declare a variable • Declare a variable named bodyTempcapable of holding a floating point value.

  5. Declare and initialize a variable • Declare a variable named bodyTempcapable of holding a floating point value. • Give it the initial value 98.6.

  6. Declare and initialize a constant • Declare a constant named NORMAL_BODY_TEMP and give it the initial value 98.6.

  7. Use the Math Library • Print the value of Pi.

  8. Use the Math Library • Given the variable radius that represents the radius of a circle, create variables named area and circumference and assign them the area and circumference of the circle.

  9. Type Compatibility • If you have the variables of the types defined below: • byte b; double d; • float f; inti; • long l; short s; • Which of the assignments are valid? • i = b; • i = d; • i = f; • i = l; • i = s;

  10. Type Compatibility • If you have the variables of the types defined below: • byte b; double d; • float f; inti; • long l; short s; • Which of the assignments are valid? • l = b; • l = d; • l = f; • l = i; • l = s;

  11. Type Compatibility • If you have the variables of the types defined below: • byte b; double d; • float f; inti; • long l; short s; • Which of the assignments are valid? • d = b; • d = l; • d = f; • d = i; • d = s;

  12. Expressions • Give the type and values of each of the following expressions. • 2 * 3 • 2 % 3 • 2 / 3 • 2 + 3 • 2.0 * 3 • 0 % 3 • 2.0 / 3 • 24 % 3

  13. Expressions • Give the type and values of each of the following expressions. • 4 + 2 * 3 • 4 - 3 - 2 • 4 * 2 % 3 • 4 % 3 * 2 • 10 / 3 / 2.0 • 2.0 + 4 / 6 • 2.0 * 4 / 6 • 23 % 8 % 2

  14. Random Numbers • Create a variable named r that can generate random numbers.

  15. Random Numbers • Using the Random variable r, assign a random integer between 0 and 10 inclusive to the integer variable val.

  16. Random Numbers • Using the Random variable r, assign a random integer between 1 and 10 inclusive to the integer variable val.

  17. Random Numbers • Using the Random variable r, assign a random even integer between 1 and 10 inclusive to the integer variable val.

  18. Random Numbers • Using the Random variable r, assign a random integer between min and max, where min ≤ max , the integer variable val.

  19. Random Numbers • Using the Random variable r, assign a random double between 0 and 1.0 to the double variable val.

  20. Random Numbers • Using the Random variable r, assign a random double between 0 and 10.0 to the double variable val.

  21. Random Numbers • Using the Random variable r, assign a random double between 100.0 and 150.0 to the double variable val.

More Related