Syamsul Hussin

Ranch Hand

Posts: 59

posted 14 years ago

hi, this is my school's past year exam question, i can't spot the error.Can anyone point it out to me. thanks.

---------

The method given below is intended to find the number that is the minimum of all the numbers in

the Vector v that are larger than the minimum of the elements in v. You may assume that v contains

at least two elements, and that that the first two elements are different numbers.

i. Describe a vector of Integers that will give the correct result using the above method.

[2 marks]

ii. Describe a vector of Integers that will give incorrect results using the above method.

[2 marks]

iii. Outline how you would go about repairing the fault in the program so it would give correct

results with both your tests. [2 marks]

[ October 26, 2006: Message edited by: Syamsul Hussin ]

---------

The method given below is intended to find the number that is the minimum of all the numbers in

the Vector v that are larger than the minimum of the elements in v. You may assume that v contains

at least two elements, and that that the first two elements are different numbers.

i. Describe a vector of Integers that will give the correct result using the above method.

[2 marks]

ii. Describe a vector of Integers that will give incorrect results using the above method.

[2 marks]

iii. Outline how you would go about repairing the fault in the program so it would give correct

results with both your tests. [2 marks]

[ October 26, 2006: Message edited by: Syamsul Hussin ]

----------------------------------<br />SCJP 1.4

Syamsul Hussin

Ranch Hand

Posts: 59

posted 14 years ago

If your minimum number is duplicated: i.e., {8, 9, 10, 8} the function will return 8 instead of 9. (The instructions only state that the first two elements are different; it says nothing about the uniqueness of these numbers)

(Edit begins here, after I saw your reply)

The else if has nothing to do with it, me thinks. It gives the same result

[ May 22, 2003: Message edited by: Joel McNary ]

(Edit begins here, after I saw your reply)

The else if has nothing to do with it, me thinks. It gives the same result

[ May 22, 2003: Message edited by: Joel McNary ]

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.