CSI1102
Quiz 2
Q1. [2 mark]
Determine the validity of the following statements.
(T/F) 1.
Data declared private at the class level can be used only by methods declared
private within the class.
(T/F) 2. You must write a constructor for each
class that you define.
(T/F) 3. Passing the actual parameters to the formal parameters is an assignment operation.
(T/F) 4. Changing the value of a static variable in one object changes it for all others of the same class.
Q2. [3 marks]
Write a short code that to reverse an integer number. For example, an integer 123 should be reversed to 321; however, your code should work with any integer of any number of digits. Also, assume that the number is given in a variable number so you do not have to ask the user to input the number again.
int currentDigit, reverse = 0;
do{
currentDigit
= number % 10;
reverse = (reverse
* 10) + currentDigit;
number = number / 10;
}
while
(number > 0);
System.out.print("The number reversed = " + reverse);
Last Name: |
|
First Name: |
|
Student number: |
|
Section: |
|