The BritishInternational School
www.bis.k12.tr
www.thebiscomputing.com

Java Programming

IGCSE Computer Science (0478) · Class Test
⏱ 60 minutes 60 questions Total: 100 marks

Instructions to Candidates

A

Multiple Choice

25 marks

Choose the one correct answer. (1 mark each)

A1. Which Java keyword declares a constant? [1]

A2. In Java the first element of an array has index: [1]

A3. Output of int[] arr={3,6,9,12}; System.out.println(arr[2]); [1]

A4. Which loop is guaranteed to run at least once? [1]

A5. After int x = 7; x++; the value of x is: [1]

A6. Which operator returns the remainder of a division? [1]

A7. Which method reads a line of input from a BufferedReader called br? [1]

A8. How many times does for(int i=1; i<=5; i++) repeat? [1]

A9. The logical AND operator in Java is: [1]

A10. For int[] nums={10,20,30,40};, nums.length is: [1]

A11. Which converts the String "25" into an int? [1]

A12. Which line correctly creates a BufferedReader for keyboard input? [1]

A13. The method readLine() returns a value of type: [1]

A14. Which import is needed to use BufferedReader? [1]

A15. Which symbol means not equal to in Java? [1]

A16. Which statement about a variable is correct? [1]

A17. Output of int a=10, b=3; System.out.println(a % b); [1]

A18. Output of int a=10, b=3; System.out.println(a / b); [1]

A19. Which data type stores a whole number? [1]

A20. Which data type is best for the value 3.14? [1]

A21. The logical OR operator in Java is: [1]

A22. Which statement correctly performs totalling? [1]

A23. Which statement correctly performs counting? [1]

A24. Which symbol means greater than or equal to? [1]

A25. For int[] a={5,10,15}; the last valid index is: [1]

B

Match the Following

8 marks

Choose the correct meaning for each Java element. (1 mark each)

==
!=
final
%
.length
&&
||
while
C

True or False

10 marks

Decide whether each statement is true or false. (1 mark each)

C1. In Java the first array index is 1.
C2. The keyword final is used to declare a constant.
C3. A do...while loop always runs at least once.
C4. Integer.parseInt() changes a String into an int.
C5. count++; increases count by 1.
C6. readLine() returns a value of type int.
C7. The % operator gives the quotient of a division.
C8. Nesting means placing one construct inside another (e.g. an if inside a loop).
C9. A for loop is best when the number of repeats is known in advance.
C10. arr.length gives the index of the last element.
D

Find the Error

16 marks

Each snippet has a mistake. State the error and the fix. (2 marks each)

D1. [2]

if (num % 2 = 0) {
    System.out.println("Even");
}

D2. [2]

int i = 1, n = 5;
while (i = n) {
    System.out.println(i);
    i +;
}

D3. [2]

int[] marks = {78, 85, 92};
System.out.println(marks[3]);

D4. [2]

BufferedReader br =
    new BufferedReader(new InputStreamReader(System.in));
int num = br.readLine();

D5. [2]

int[] data = {30, 65, 80};
int count = 0;
for (int i = 0; i < data.length; i++) {
    if (data[i] > 50)
        count + 1;
}
System.out.println(count);

D6. [2]

final int LIMIT = 50;
LIMIT = LIMIT + 10;
System.out.println(LIMIT);

D7. [2]

int[] a = {10, 20, 30};
for (int i = 0; i <= a.length; i++) {
    System.out.println(a[i]);
}

D8. [2]

int age = 20;
if (age >= 18) {
    System.out.println("Adult")
}
E

Correct the Code

16 marks

Rewrite each snippet so it works correctly. (4 marks each)

E1. Should display the numbers 1 to 5. [4]

int i = 1, n = 5;
while (i = n) {
    System.out.println(i);
    i +;
}

E2. Should print the total of all array elements. [4]

int[] arr = {4, 8, 15, 16, 23};
int sum;
for (int i = 1; i <= arr.length; i++) {
    sum = arr[i];
}
System.out.println("Sum: " + sum);

E3. Should count how many numbers are greater than 50. [4]

int[] data = {30, 65, 80, 20, 90};
int count;
for (int i = 0; i <= data.length; i++) {
    if (data[i] > 50) {
        count = count + 1
    }
}
System.out.println("Above 50: " + count);

E4. Should read two numbers and print their sum. [4]

BufferedReader br =
    new BufferedReader(new InputStreamReader(System.in));
int a = br.readLine();
int b = br.readLine();
int sum = a + b;
System.out.println(sum)
F

Programming Questions

25 marks

Write complete Java programs using BufferedReader br for input. (5 marks each)

F1. Write a program that reads five integers from the user into an array, displays them all using a loop, and finds and displays the largest value. [5]

F2. A worker enters the weight of each sack of rice; entering −1 stops the program. Write a program (condition-controlled loop) that counts the sacks and totals their weights, then outputs both. [5]

F3. Write a program that reads a number and states whether it is positive, negative or zero; if it is positive, it should also state whether it is even or odd (use nested selection). [5]

F4. Bank ATM Withdrawal System. Write a program that:
• takes the account balance and the withdrawal amount;
• checks if the balance is sufficient;
• if it is → deduct the amount and show the remaining balance;
• if it is not → show "Insufficient balance". [5]

F5. A shop records the number of items sold each day for seven days. Write a program that reads the 7 values into an array, then displays the total sold for the week and the day number (1–7) with the highest sales. [5]