kristofer gist felülvizsgálása . Revízióhoz ugrás
1 file changed, 23 insertions
WhoaWhat.java(fájl létrehozva)
| @@ -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 | + | } | |
Újabb
Régebbi