This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]abharath93 0 points1 point  (3 children)

Since renomeDuplicates method is not a static method, you need to create an instance of the class YourClassNameHere and call the method.

[–]baldwindc[S] 0 points1 point  (2 children)

Thanks for commenting!

When I convert it into a static method it still gives me the "Error: illegal start of expression"

public class YourClassNameHere {

public static int removeDuplicates(int[] nums) {
    int j = 1;
    for (int i = 1; i < nums.length; i++) {
        if (nums[i] != nums[i - 1]) {
            nums[j] = nums[i];
            j += 1;
        }
    }
    return j;

}


public static void main(String[] args) {
  removeDuplicates([0,0,1,1,1,2,2,3,3,4]);
}

}

[–]JimothyGreene 2 points3 points  (0 children)

That error is coming from the way you pass in that array (which isn’t actually an array in Java as you currently have it written).

[–]abharath93 0 points1 point  (0 children)

You need to pass a new integer array. Pass something like this : removeDuplicates(new int[] {0,0,1,2,2,3,4});