1. Write a method called moveDown that deletes the element at index spot and moves the elements down to fill the gap. If spot is out of bounds, the method does nothing.
Use the signature: public static void moveDown (char[] goodies, int spot)
Ok so here's what I have for that method:
public static void moveDown (char[] goodies, int spot)
{
for (int i = 0; i < goodies.length; i++)
{
goodies [i]--;
spot--;
}
}
2. Write a method called moveUp that inserts one new element at index spot and moves the elements up to make room for the new element. When moving the elements up, the originally last element will cease to exist. If spot is out of bounds, the method does nothing.
Use the signature: public static void moveUp (char[] goodies, int spot, char newElement)
Here's what I have for this, and I know it is quite wrong, I can't come up with a way to do this one though...
public static void moveUp (char[] goodies, int spot, char newElement)
{
for (int i = 0; i < goodies.length; i++);
{
goodies [i]++;
spot++;
}
}
Finally 3. Write a method called reverser that reverses the order of elements in an array.
Use the signature: public static void reverser (char[] goodies)
And here's what I have that I believe to be correct for this one:
public static void reverser (char[] goodies)
{
{
char temp;
char[] start = {'g', 'o', 'o','d', 'y'};
char[] end = {'y', 'd', 'o','o','g'};
temp = goodies[start];
goodies[start] = goodies[end];
goodies[end] = temp;
reverser(goodies);
}
}
Thanks so much for your help!

New Topic/Question
Reply



MultiQuote




|