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?
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;
}
}