I am teaching myself Java and am getting this error when I run code in my scrap book in Eclipse:
Syntax error, insert "AssignmentOperator Expression" to complete Expression
Here is my scrap book:
Sorter sorter = new Sorter();
int[] nums = {5, 6, 7, 8, 1, 2, 3, 4};
sorter.selectionSort(nums);
nums;
Here is the Sorter class.
public class Sorter {
public void selectionSort(int[] numbers) {
for (int i = 0; i < numbers.length - 1; i++) {
int leastPosition = i;
for (int j = i + 1; j < numbers.length; j++) {
if (numbers[j] < numbers[leastPosition])
leastPosition = j;
}
int temp = numbers[leastPosition];
numbers[leastPosition] = numbers[i];
numbers[i] = temp;
}
}
}
What is awry? I can’t find a missing assignment operator anywhere.
The problem, I think, is the last line of your code:
This is an expression, but not a statement; hence the complaint. If you want to examine the contents of
nums, you can do something like: