There is no such thing as passing by reference in Java, sorry :(
Your options are either to give the method a return value, or use a mutable shell and set the value as you move. Using AtmoicInteger results in it being in the JDK, so your own, which doesn't care about thread safety, will of course be moderately faster.
AtomicInteger metric = new AtomicInteger(0); calcSim(fort, metric); System.out.println("metric: " + metric.get());
Then inside calcSim, install it using metric.set(int i);
source share