Professional Documents
Culture Documents
preUPS 2 SET 2
preUPS 2 SET 2
preUPS 2 SET 2
1 Identifier is the name that identifies the elements such as classes, methods, and
variables in a program that is written according to specific rules and naming
conventions.
Identify the invalid identifier and justify the reason based on the given declaration
statement.
[2 marks]
double gross_salary, income_tax, final, MonthlySalary;
_____________________________________________________________________
_____________________________________________________________________
2 Data types are especially important in programming because it helps prevent errors and
enhances reliability.
(a) Identify the data type for a variable named choice that can hold a single
character ‘Y’ or ‘N’ input by a user.
[1 mark]
_______________________________________________________________
(b) FIGURE 1 shows the output for a program that displays the value of variables
a and b. Write the declaration statement for variables a and b.
[1 mark]
FIGURE 1
_______________________________________________________________
(c) Write a declaration statement to declare a variable named no_athletes that
can hold a whole number.
[1 mark]
_______________________________________________________________
3 State two (2) types of operators that are used in the given Java expression.
[2 marks]
((value1 == 1) && (value2 == 2))
_____________________________________________________________________
_____________________________________________________________________
4 Write a Java statement to do the following:
FIGURE 1
100 99 98 97 96 Y
X
FIGURE 2
(a) Identify X and Y.
[2 marks]
_______________________________________________________________
_______________________________________________________________
(b) State the arrayRefVar/array name.
[1 mark]
_______________________________________________________________
8 Write a Java statement (s) to declare and create a new array named marks to store
15 students’ marks that have decimal points.
[2 marks]
_____________________________________________________________________
_____________________________________________________________________
(a) Write a Java statement to display the sum of the first two elements in the
given array.
[1 mark]
______________________________________________________________
(b) Assign the value 60.0 to the last element in the array.
[1 mark]
_______________________________________________________________
10 Write a loop statement that allows a user to enter data into an array named
NoOfStudent that holds 30 integer values. Assume all the variables and input (a
scanner object) have been properly declared.
[4 marks]
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
END OF QUESTIONS