This may be a duplicate question but I couldnt find what I am searching. If it exists, sorry about duplication.
I want to learn that if the following part of codes are same in terms of memory allocation.
//first
int n = some_number;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
int a = something;
}
}
//second
int i, j, a;
for(i = 0; i < n; i++){
for(j = 0; j < n; j++){
a = something;
}
}
I wonder, if java allocates the variable a
n^2 times and j
n times in the first code or both are allocated only once as in the second code.
I tried this couple of times in java but the results are inconsistent like in one trial first is 8 sec, second is 9 sec, in another trial reverse. So, I want to make sure if they are equal or not,
Thanks