I have code in which what the switch statement is testing depends on an array variable:
String shuff = Import.shuffle();
String[] form = new String[95];
for(int i = 0; i < 95; i++)
{
form[i] = Format.shuffle(shuff, i);
}
switch(str)
{
case "a":
x = 6;
break;
case "b":
x = 16;
break;
case "c":
x = 23;
break;
}
What I want to do is take the form of the array [] and use it as an example:
String shuff = Import.shuffle();
String[] form = new String[95];
for(int i = 0; i < 95; i++)
{
form[i] = Format.shuffle(shuff, i);
}
switch(str)
{
case form[0]:
x = 6;
break;
case form[1]:
x = 16;
break;
case form[2]:
x = 23;
break;
}
But when I try to do this, it gives the error "case expressions must be constant expressions." Two solutions come to mind, but I do not know how to do it. 1. Use an array in the switch case somehow 2. use some method that will look like this ...
String shuff = Import.shuffle();
String[] form = new String[95];
for(int i = 0; i < 95; i++)
{
form[i] = Format.shuffle(shuff, i);
}
switch(str)
{
case form[0].toString():
x = 6;
break;
case form[1].toString():
x = 16;
break;
case form[2].toString():
x = 23;
break;
}
Is there any way to do this?
The Import.shuffle method accepts a text file with 95 lines (each line is a single character) and concatenates them together, and Format.shuffle puts each of the source lines in separate array variables.
if else if, 95- (edit)