0% found this document useful (0 votes)
42 views4 pages

preUPS 2 SET 3

This document contains a 10 question practice exam on Java programming concepts. The questions cover topics like data types, operators, arrays, loops, and errors. Students are asked to identify valid code, find errors, write code segments, and determine outputs.

Uploaded by

thisisacoralreef
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views4 pages

preUPS 2 SET 3

This document contains a 10 question practice exam on Java programming concepts. The questions cover topics like data types, operators, arrays, loops, and errors. Students are asked to identify valid code, find errors, write code segments, and determine outputs.

Uploaded by

thisisacoralreef
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

SET 3

PRE UPS 2 (SC025)

Instruction: Answer all the following questions.

1. An identifier is a name given to elements in a program commonly used to represent a


class name, variable name, method name or parameter name.

(a) Identify whether each of the following identifiers is valid or invalid.


[2 marks]

No Identifier Valid / Invalid

(i). 1Malaysia

(ii). UPS 2

(b) Give one (1) reason why keywords such as true, else, and import
cannot be used as an identifier.
[1 mark]
_______________________________________________________________
2. Identify the most suitable data type to be used based on the given statement.
[2 marks]
(a) To store the average of 50 marks entered by a lecturer.
_______________________________________________________________
(b) To store the gender of a student.
_______________________________________________________________
3. Given the following declaration:
int y;
What is the value stored in variable y after the following statements are executed?
[2 marks]
(a) y = 40/100;
_______________________________________________________________
(b) y = 20%40;
_______________________________________________________________
4. Identify the type of operators based on the given Java Expressions.
[2 marks]

No Java Expressions Type of Operator


(a) x || y
(b) 13 / 5 % 2
5. Determine the output based on the given Java expression.
[3 marks]

No Java Expression Output


(a) !((5==5) && (3!=5))
(b) (15/4) % 2.0
(c) ((18 + (18 / 9)) >= (100 – 20) / 4)

6. Consider the following Java code snippet:

1 int x = 10;
2 int y = 3;
3 int z = 0;
4 int ans1 = x / y;
5 int ans2 = x / z;

Answer the following questions:

(a) State the line number that contains an error.


[1 mark]
____________________________________________________________________

(b) State and describe the type of programming error mentioned in 6(a).
[2 marks]
____________________________________________________________________

7. A loop is a programming construct that is used to repeatedly run a given section of


code. For example, if we want to check the grade of every student in the class, the loop
will begin from 1 until the last number of students. However, there are a few limitations
in the loop and the array comes in handy.

(a) Define an array.


[2 marks]
_______________________________________________________________
_______________________________________________________________
(b) State one (1) component of an array.
[1 mark]
_______________________________________________________________
_
8. FIGURE 1 shows an example of an array.

marks[0] marks[1] marks[2] marks[3] marks[4] marks[5]


89 68 79 100 90 78

FIGURE 1
Write Java statement(s) to accomplish the following based on an array shown in
FIGURE 1.
(a) Declare and create the given array.
[1 mark]
_______________________________________________________________
(b) Display the difference between the fourth and fifth elements.
[1 mark]
_______________________________________________________________
(c) Assign the value 65 to the third element in the array.
[1 mark]
_______________________________________________________________
9. Answer the following question based on the given Java segment.

Scanner get = new Scanner(System.in);


int i, student = 10;
double [ ] quiz1 = new double[student];
double [ ] quiz2 = new double[student];
double [ ] avgQuiz = new double[student];

(a) Complete the given for statement to read both quiz1 and quiz2 marks for all
students into a respective array.
[2 marks]
for (int i=0; i<student.length; i++)
{

_________________________________________________________
_________________________________________________________
_________________________________________________________
}

(b) Write a Java statement (s) to calculate the average mark for each student and
assign it to the corresponding array.
[2 marks]
_______________________________________________________________
_______________________________________________________________
10. Consider the program segment as below. Write the first and last output.

int [ ] number = {0,1,2,3,4};


for (int n=4; n<-1; n=n-1)
{
System.out.println(“going_” + number[n]);
}
[2 marks]
_____________________________________________________________________
_____________________________________________________________________

END OF QUESTION PAPER

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy