CSCI 1111 Lecture Notes - Lecture 3: Operand, Pseudorandom Number Generator, Type Conversion
Document Summary
A variable need to store a decimal occasionally: defined as type double stores a floating point number. A floating point literal is a number with a fractional part (0. 0, 99. 5) Using scientific notion is written as e (6. 02e23 = 6. 02 * 1023) Programming example: given sphereradius and pival, compute the volume of a sphere and assign to spherevolume, use (4. 0/3. 0) to perform floating point division. The keyword final makes a variable constant, and unchanging cannot be modified. An input value to a method goes between parentheses and is known as an argument. Using a math method from the math class: double sidesquare = 0. 0, double areasquare = 49. 0, sidesquare = math. sqrt(areasquare) Example computing the volume of a sphere: spherevolume = (4. 0/3. 0) * pival * math. pow(sphereradius,3); A calculation must mix integer and floating point numbers sometimes. A type conversion is a conversion of one data type to another (int to double)