Limited access

Which of the following methods will return an array of single positive digits containing the tens position of each corresponding element from nums?

Note: If the element is only a single digit (i.e. there is no tens position), the corresponding element in the returned array will be -1.

For example, if nums = {231, 45, 6, -92}, then this method should return {3, 4, -1, 9}.

I.

public static int[] getTensDigit(int[] nums)
{
for (int i=0; i<nums.length; i++)
{
String n = nums[i] + "";
nums[i] = n.substring(n.length()-2, n.length()-1);
if (nums[i]>-10 && nums[i]<10 )
nums[i]=-1;
}
}


II.

public static int[] getTensDigit (int[] nums)
{
int[] tensDigit = new int[nums.length];
for (int i=0; i<nums.length; i++)
{
if (nums[i]>-10 && nums[i]<10 )
tensDigit[i]=-1;
else
tensDigit[i] = Math.abs((nums[i]%100)/10);
}
return tensDigit;
}


III.

public static int[] getTensDigit (int[] nums)
{
int[] tensDigit = new int[nums.length];
for (int i=0; i<nums.length; i++)
{
if (nums[i]>-10 && nums[i]<10 )
{
nums[i]=-1;
tensDigit[i]=-1;
}
}
for (int i=0; i<nums.length; i++;
{
if (nums[i]>0 )
tensDigit[i] = nums[i]%100/10;
}
return tensDigit;
}

A

I only.

B

II only.

C

III only.

D

I and II only.

E

II and III only.

Select an assignment template