I have this chunk of code that I've been having problems with:
int n = 5;
String[] variables = new String[31];
//user input defining the strings in the array
for(int i = 1; i < n+1; i++)
{
System.out.print("Define variable " + i + ": ");
variables[i] = System.console().readLine();
System.out.println("Variable " + i + " has been set to " + variables[i]);
}
int vfirstDigit;
//some irrelevant code excluded
for(int firstDigit = 1; firstDigit < n+1; firstDigit++)
{
switch(firstDigit)
{
case 1:
vfirstDigit = variables[1];
break;
}
}
When I call variables[1] in the switch statement, the compiler flags it as an error, saying the String array cannot be converted to an integer. Why does calling a specific string in the array convert it to an integer, when the user input must be characters? Pretty sure I'm doing something wrong here.