2003SCTestQuestions

Questionanswer sheet page 9 compsci 101 s2 surname

• Notes
• UltraLightningCobra8457
• 16

This preview shows page 9 - 13 out of 16 pages.

Question/Answer Sheet - Page 9 - COMPSCI 101 S2 SURNAME: ...................................................... FORENAMES: ........................................................... (f) If either c is equal to d or both a is 7 and b is less then 10, then set result to 6 (2 marks) (g) If d and e are both less than 7 and either f or g are equal to b, then set result to 9 (2 marks) (h) If both c and b are equal to 5 and neither e nor f are equal to 6 then set result to 5 (2 marks) (i) If a is less than 10, then set result to 7, unless b is greater than 10. (2 marks) (j) If c is between a and b (inclusive), then set result to 10, unless c is equal to e or f (2 marks)

Subscribe to view the full document.

Question/Answer Sheet - Page 10 - COMPSCI 101 S2 SURNAME: ...................................................... FORENAMES: ........................................................... Question 6 (5 marks) What is the output when the following section of code is executed? int currentValue = 0; int addOn = 5; for(int i=0; i<26; i=i+addOn){ System.out.println("i: " + i); if (i > 10){ addOn++; } currentValue = currentValue + addOn; } System.out.println("Current Value: " + currentValue); Write the output here: (5 marks)
Question/Answer Sheet - Page 11 - COMPSCI 101 S2 SURNAME: ...................................................... FORENAMES: ........................................................... Question 7 (10 marks) Write the method, sumDigits(). This method is passed one parameter, a String of digits. The method returns the sum of the digits in the String . For example, when the following code is executed with the completed sumDigits() method: String numbersString = "314052"; System.out.println(numbersString); System.out.println("Sum of Digits: "+ sumDigits(numbersString)); System.out.println(); numbersString = "839"; System.out.println(numbersString); System.out.println("Sum of Digits: "+ sumDigits(numbersString)); the output is: 314052 Sum of Digits: 15 839 Sum of Digits: 20 private static int sumDigits(String numString){ } (10 marks)

Subscribe to view the full document.

Question/Answer Sheet - Page 12 - COMPSCI 101 S2 SURNAME: ...................................................... FORENAMES: ........................................................... Question 8 (10 marks) Write the method, arrangeNums(). This method is passed one parameter, an array of int s. The parameter int array has all its elements filled with positive non zero values. The method returns a new int array containing the same numbers as the parameter array except that all the even numbers are at the beginning of the array and all the odd numbers are at the end of the array. The ordering of the numbers is not changed e.g. position 0 of the return array contains the first even number from the parameter array, position 1 of the return array contains the second even number from the parameter array, etc. Note: The following code makes use of a method called printArray(). This method is not shown below.
You've reached the end of this preview.
• Summer '12
• Computer Science, English-language films, Subroutine, ........., Equals sign, ASCII

{[ snackBarMessage ]}

What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern