Beginner Array Problem. Swapper
SOLVED!
This is what i have and I am not sure what i am doing wrong. It keeps giving me errors!
Code :
public class Swapper
{
public static void main(String[] args){
public void swapFirstAndSecondHalf(int[] values)
{
int[] a = {1,2,3,4,5};
int k = 0;
int temp = 0;
while(k < a.length/ 2)
{
temp = a[k];
a[k] = a[a.length -1-k];
a[a.length-1-k] = temp;
k++;
}
}
// This method is used to check your work
public int[] check(int[] values)
{
swapFirstAndSecondHalf(values);
return values;
}
}
}
Any help would be greatly appreciated!
Re: Beginner Array Problem. Swapper
Hint - don't put methods inside of methods. main() is a method. swapFirstAndSecondHalf() is a method.
Re: Beginner Array Problem. Swapper
Would i fix that by making a new class?
Re: Beginner Array Problem. Swapper
Try moving the method outside of the {}s that surround the code for the main() method.
You may not need a new class.
Re: Beginner Array Problem. Swapper
I am not sure what you mean. Should i write the code where the main method has nothing in it and then separate it?
thank you Norm
Re: Beginner Array Problem. Swapper
To correct the compiler error, make sure that no methods are defined inside of other methods.
Make that change, get a clean compile and THEN write code for the main() method.
One step at a time.
Re: Beginner Array Problem. Swapper
I have been trying to do that for the last few hours. :( It keeps giving me back errors.
Re: Beginner Array Problem. Swapper
Show the code and Post the full text of the error messages if you want help with them.
Re: Beginner Array Problem. Swapper
the issue is now resolved. Thank you very much for your help. I ended up not using a second class. Thank you norm.