Posted now on several websites, I am looking still for one Java expert to figure out the answer without running the code:
public class MeaningOfLife {
public static String findOutWhatLifeIsAllAbout() {
int meaning = 0;
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 20; j++) {
for (int k = 0; k < 300; k++) {
for (int m = 0; m < 7000; m++) {
meaning += Math.random() + 1;
}
}
}
}return String.valueOf(meaning).replaceAll("0*$", "");
}
public static void main(String[] args) {
System.out.println(findOutWhatLifeIsAllAbout());
}
}
Think about what the output should be before you run it. Then try it out, preferably with the -server switch. On my machine it takes 15 seconds to find the meaning of life with -server and 25 seconds with -client. Patience is apparently a virtue.
The question is: Why is it giving this result? And why does it even compile?