int loc = 0 ;
int place = loc*3+1;
ArrayList<String> map = new ArrayList<String>(
Arrays.asList("|"," ","|\n", "|"," ","|\n", "|"," ","|\n",
"|"," ","|\n", " ‾\n"));
Above is my Array list and some variables to keep track of the location of the spaces inside the array list. the Arraylist's purpose is to create a little map when its printed. The map looks like below. The blank spaces, where the character can be can be found every three index values at 1,4,7,and 10.
| |
| |
| |
| |
‾
The method I am having trouble with is below. Its purpose is to check if there is a blank space "above" the character. If there is a blank space it will return the word North and if there isn't it should return No.
public static String moveN( ArrayList<String> map, int place){
String movenorth = "";
String positionvalue = map.get(place-3);
if (place-3 <= 0){
movenorth = "No";
} else {
if (positionvalue.equals(" "))
movenorth = "North";
}
return(movenorth);
}
Instead of returning No, it returns
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -2
How might I get around this as my if statement is obviously not working as I wanted it to.