Skip to content

Instantly share code, notes, and snippets.

@nitsanw
Created January 25, 2016 09:49
Show Gist options
  • Save nitsanw/a8b20fc6ecbb9ae9c054 to your computer and use it in GitHub Desktop.
Save nitsanw/a8b20fc6ecbb9ae9c054 to your computer and use it in GitHub Desktop.
public class WhenWillItExitInt3 {
public static void main(String[] argc) throws InterruptedException {
for (int i=0;i<100000;i++) {
countOdds(10);
}
Thread t = new Thread(() -> {
long l = countOdds(Integer.MAX_VALUE);
System.out.println("How Odd:" + l);
});
t.setDaemon(true);
t.start();
Thread.sleep(5000);
}
private static long countOdds(int limit) {
long l = 0;
for (int i = 0; i < limit; i++) {
for (int j = 0; j < limit; j++) {
if ((j & 1) == 1)
l++;
}
}
return l;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment