11.1 Programming Basics (3)

Resources | Revision Questions | Computer Science

Login to see all questions

Click on a question to view the answer

1.

Question 2

The following structured English describes an algorithm to calculate the area of a rectangle. Write pseudo-code to represent this algorithm.

Structured English:

START

Input the length of the rectangle, length.

Input the width of the rectangle, width.

Calculate the area: area = length * width.

If area is positive, then output "The area is positive".

Else, output "The area is zero or negative".

END

2.

Write a function in Java that takes a 2D array of integers as input and calculates the sum of all the elements in the array. You must use the Arrays.stream() library routine. Your function should handle the case where the input array is null or empty. Provide a clear explanation of your code.

3.

Write pseudo-code statements to declare three integer variables: age, score, and attempts. Each variable should be assigned an initial value of 0.