Answer the question
In order to leave comments, you need to log in
Is it possible to access a variable outside of a function?
Hello! I'm just learning the Java language and there was a problem when writing the code. Is there any way I can refer to an int variable outside of a function/method ? Thanks in advance for the help
actually the code
static int Current(int [][] m) {
Sys.pln(" Move from which cell?");
int i = Sys.readInt();
int j = Sys.readInt();
int current = m[i][j];
return current;
}
static int Target(int [][] m) {
Sys.pln("Which one?");
int i = Sys.readInt();
int j = Sys.readInt();
int target = m[i][j];
return target;
}
public void doMotion(int[][] m){
current=target; - error
}
This is something like working with an 8x8 matrix to create a checkers board, I'm trying to make a move with a checker
Answer the question
In order to leave comments, you need to log in
If the method is not static, you can refer to any class variable.
If static - then only to a static variable.
Handles would be torn off for this, cases when it is justified nothing at all ... getters, setters are our everything)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question