CPT121-Task 1.1.3 Variables, Types and Casting Solved
1. Give appropriate declarations (type and name) for variables used to store the following values:
a) An employee's taxable salary e) The average rainfall for the past month
b) The month number within a year f) A letter to hold an answer (‘y’ or ‘n’)
c) An employee identification number g) The constant string "Hello"
d) The capacity of a tank in cubic inches h) The conversion rate from $AUS to $US
2. Assuming that the types of the variables x, y, and z are int, float and double respectively, which of the following statement(s) are likely to result in error ?
a) x = y; b) x = z; c) y = x;
d) y = z; e) z = x; f) z = y;
3. The following code segment prints an incorrect result (instead of the expected result of sqr = 10000000000 ).
int num1 = 100000; int sqr = num1 * num1;
System.out.println("sqr = " + sqr);
Describe the problem / error that has occurred and suggest a solution or work-around to the problem which will allow the correct result to be stored and printed.