public class ArrayWorker
{
private int[ ] values;

public ArrayWorker(int[] theValues)
{
values = theValues;
}

public void doubleFirstFive()
{
for (int i = 0; i < values.length && i < 5; i++)
{
values[i] = values[i] * 2;
}
}

public void printArray()
{
for (int val: values)
{
System.out.println(val);
}
}

public static void main(String[] args)
{
int[] numArray = {3, 8, -3, 2, 20, 5, 33, 1};
ArrayWorker worker = new ArrayWorker(numArray);
worker.doubleFirstFive();
worker.printArray();
}
}

public class ArrayWorker
{
private int[ ] values;

public ArrayWorker(int[] theValues)
{
values = theValues;
}

public void doubleLastHalf()
{
for (int i = values.length / 2; i < values.length; i++)
{
values[i] = values[i] * 2;
}
}

public void printArray()
{
for (int val: values)
{
System.out.println(val);
}
}

public static void main(String[] args)
{
int[] numArray = {3,8,-3, 2};
ArrayWorker worker = new ArrayWorker(numArray);
worker.doubleLastHalf();
worker.printArray();
}
}

0:00

Given the following values of a and the method doubleLast what will the values of a be after you execute: doubleLast()?

private int[ ] a = {-20, -15, 2, 8, 16, 33};

public void doubleLast()
{

for (int i = a.length / 2; i < a.length; i++)
{
a[i] = a[i] * 2;
}
}
i3开始增加。
3

Given the following values of a and the method mystery what will the values of a be after you execute: mystery()?

private int[ ] a = {-20, -15, 2, 8, 16, 33};

public void mystery()
{

for (int i = 0; i < a.length/2; i+=2)
{
a[i] = a[i] * 2;
}
}

4