The following method should find and
return the smallest number in an array.
It is incorrect -
every line contains one error (or more).
Some of them are
syntax errors, others are logic
errors.
Read the code and try to find each error. Then look at
the correct solution.
public void findSmallest(int[] nums)
{
int
smallest = 0;
for(int p = 0; p < 10; p =
p+1)
{
if
(nums[p] > smallest)
{
nums[p]
= smallest;
}
}
return nums[smallest];
}
public int findSmallest(int[]
nums)
{
int smallest =
nums[0];
for(int p = 0; p < nums.length; p
= p+1)
{
if
(nums[p] <
smallest)
{
smallest = nums[p];
}
}
return
smallest;
}