Question 19 6 marks fill in the spaces below a should

This preview shows page 3 - 7 out of 8 pages.

Question 19 (6 marks) Fill in the spaces below: a) Should evaluate to 5: int number = calculate( 0 , 5 ); b) Should evaluate to 2: int number = calculate( 0 , 2 ); (6 marks) Question 20 (6 marks) Show the output below. 1. Result: 17 2. Result: 9 (6 marks) Question 21 (16 marks) Complete the code in the space provided below a) private int getRandomNumber(int value) { return (int) (Math.random() * value); } NB: this is one of many possible answers NB: this is one of many possible answers
Image of page 3

Subscribe to view the full document.

Answer Sheet - 4 - COMPSCI 101 ID ........................................ CONTINUED b) private void printDescription( String name , int age ) { System.out.println(name + " is age: " + age); } c) private String getLonger( String word1, String word2 ) { if (word1.length() >= word2.length() ) { return word1; } return word2; }
Image of page 4