-2

This code is generating the errors displayed in the attached picture, regarding the declaration of the variable intCounter within the method removeItem of class Remover. I cannot fathom why, and have truly scoured the internet. Could anyone explain why the compiler is not reading this declaration?

Compiler Results

import java.util.*;

class C10E3
{
    static Scanner console = new Scanner(System.in);
    public static void main(String[] args)
    {
        //declaration phase
        int[] array ={4, 23, 65, 34, 82, 37, 12, 17, 24, 36, 82, 51};
        int[] arrayUpdated = new int[11];
        int intToBeRemoved;
        Remover remove = new Remover();

        System.out.println("Which of these elements shalls be removed from thr array?");
        for (intCounter = 0; intCounter < 12; intCounter++)
            System.out.print(array[intCounter]);
        System.out.print("\n");
        intToBeRemoved = consoe.nextInt();
        arrayUpdated = remove.removeItem(array, 12, intToBeRemoved);
        System.out.print("Updated Array: ");
        for (intCounter = 0; intCounter < 11; intCounter++)
            System.out.print(array[intCounter]);
    }
}

class Remover
{
    private Vector vector = new Vector();

    public int[] removeItem(int[] array, int intArrayLength, int intToRemove)
    {
        boolean boolIsRemoved;
        int[] arrayToReturn = new int[intArrayLength - 1];
        int intCounter;

        for (intCounter = 0; intCounter < intArrayLength; intCounter++)
            vector.addElement(array[intCounter]);

        boolIsRemoved = vector.removeElement(intToRemove);
        if (boolIsRemoved == true)
            {
                for (intCounter = 0; intCounter < intArrayLength - 1; intCounter++)
                    arrayToReturn[intCounter] = vector.elementAt(intCounter);
            }
            else
            {
                System.out.println("Element not present in array.");
                for (intCounter = 0; intCounter < intArrayLength - 1; intCounter++)
                    arrayToReturn[intCounter] = array[intCounter];
            }
            return arrayToReturn;
    }
}
Damian Kozlak
  • 7,065
  • 10
  • 45
  • 51
DesPhantomes
  • 27
  • 1
  • 9
  • 2
    `intCounter` is not a variable declaration, `int intCounter` is a variable declaration. – azurefrog Dec 03 '15 at 23:23
  • `C10E3` is missing `int intCounter;` – kryger Dec 03 '15 at 23:23
  • 2
    Possible duplicate of [What does a "Cannot find symbol" compilation error mean?](http://stackoverflow.com/questions/25706216/what-does-a-cannot-find-symbol-compilation-error-mean) – kryger Dec 03 '15 at 23:24

1 Answers1

1

in main(), intCounter is not yet defined, like errors say, add a definition of it, e.g.

int intCounter;
for (intCounter = 0; intCounter < 12; intCounter++)
DBug
  • 2,502
  • 1
  • 12
  • 25