BufferedReader br for input.Select the one correct answer. (1 mark each)
A1. What does Integer.parseInt(br.readLine()) do? [1]
A2. Output of System.out.println(17 % 5); [1]
A3. Output of System.out.println(17 / 5); [1]
A4. How many elements are in int[] t = {29, 31, 30, 28};? [1]
A5. Which condition is true when num is even? [1]
A6. Inside a loop, what does i++ do? [1]
A7. For a 5-element array, for(int i=0; i<arr.length; i++) visits indexes: [1]
A8. Which keyword prevents a value from being changed? [1]
A9. To check a balance is enough to withdraw an amount, the condition is: [1]
A10. Which loop is guaranteed to run at least once? [1]
A11. What is printed? int x=4; if(x>2 && x<10) ... "yes" ... else ... "no" [1]
A12. Which statement keeps a running total? [1]
Decide whether each statement is true or false. (1 mark each)
Integer.parseInt("12.5") works and gives 12. [1]if (x = 5) correctly compares x with 5 in Java. [1]do...while loop, the body runs before the condition is checked. [1]total = total + arr[i]; is an example of totalling. [1]&& means OR. [1]State exactly what each program prints. (2 marks each)
C1. [2]
int sum = 0;
for (int i = 1; i <= 4; i++) {
sum = sum + i;
}
System.out.println(sum);
C2. [2]
int[] a = {3, 7, 2, 9, 5};
System.out.println(a[1] + a[3]);
C3. [2]
int count = 0;
int[] nums = {12, 5, 18, 3, 20};
for (int i = 0; i < nums.length; i++) {
if (nums[i] > 10) {
count++;
}
}
System.out.println(count);
C4. [2]
int n = 3;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j);
}
System.out.println();
}
Each snippet has a mistake. State the error and the correction. (2 marks each)
D1. [2]
if (denominator = 0) {
System.out.println("Division by zero is not allowed.");
}
D2. [2]
for (int i = 1; i = rows; i +) {
System.out.println(i);
}
D3. [2]
int[] sales = {95, 120, 85};
for (int i = 1; i <= sales.length; i++) {
System.out.println(sales[i]);
}
D4. [2]
int i = 1;
do {
System.out.println(i);
i++;
} while (i = 5);
Write complete Java programs using BufferedReader br for input. (8 marks each)
E1. Discount Calculation System. Read a purchase amount, then apply a discount:
• amount ≥ 5000 → 20% discount;
• amount 2000–4999 → 10% discount;
• otherwise → no discount.
Print the final amount the customer must pay. [8]
E2. Daily Temperature Tracker. Read the temperatures for 7 days into an array, then display the highest temperature and the average temperature for the week. [8]