Last active 1729274913

a small difference makes results wildly different

kristofer's Avatar kristofer revised this gist 1729274913. Go to revision

1 file changed, 23 insertions

WhoaWhat.java(file created)

@@ -0,0 +1,23 @@
1 +
2 + public class WhoaWhat {
3 + public static void main(String[] args) {
4 + System.out.println(doOne() + " " + doTwo());
5 + // will print 2048 4 - but why?
6 + }
7 + private static int doOne() {
8 + int result = 2;
9 + for(int i = 0; i < 10; i++)
10 + {
11 + result = result * 2;
12 + }
13 + return result;
14 + }
15 + private static int doTwo() {
16 + int result = 2;
17 + for(int i = 0; i < 10; i++);
18 + {
19 + result = result * 2;
20 + }
21 + return result;
22 + }
23 + }
Newer Older