Question/Answer Sheet - Page 3 - CompSci 101 SS C SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED Question 2 (5 marks) You need to locate and correct the errors in the application Q2 . What the application is supposed to do is add together two integers and print the result to the screen. For example, when the correct application is run the output should be as shown below: C:/> java Q2 The sum is: 68 The source code for the application Q2 is given below, however it is not correct - it contains five syntax errors. You need to locate the syntax errors in the source code below. For each error you must clearly circle the error and also provide a correction . You do not need to write out the whole line of source code again, as long as you indicate your correction clearly. public class Q2 /* A program to add two numbers together /* public static void pain(String[] args) { int a = 23; int b = 45; int c == sum(a, b); System.out.println("The sum is: " + c); } public int sum(int a, int b) { return a + b; } } (5 marks)

This preview
has intentionally blurred sections.
Sign up to view the full version.

Question/Answer Sheet - Page 4 - CompSci 101 SS C SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED Question 3 (10 marks) Write the method removeRandomChars() which accepts two parameters, a String and an int ; the second parameter dictates how many characters are to be removed from the String .

This is the end of the preview. Sign up
to
access the rest of the document.