I need help with arrays.
From ggc
For Array1 > firstLast6 I can get it to return in some cases but not a case in which the array only contains two or less elements. How can I fix this issue. Below is the code I tried.
public boolean firstLast6(int[] nums) {
for (int i=0; i<(nums.length-1); i++)
{
if (nums[i+0]==6 || nums[i+1]==6) return true;
}
return false;
}
Answer
Try something like:
if(nums.length==2)
{
//do something
}
and so forth for the other cases.
- This page was last modified on 2 April 2008, at 19:14.
- This page has been accessed 164 times.
- Privacy policy
- About ggc
- Disclaimers
- Powered by MediaWiki!









