WhoaWhat.java
· 522 B · Java
Brut
public class WhoaWhat {
public static void main(String[] args) {
System.out.println(doOne() + " " + doTwo());
// will print 2048 4 - but why?
}
private static int doOne() {
int result = 2;
for(int i = 0; i < 10; i++)
{
result = result * 2;
}
return result;
}
private static int doTwo() {
int result = 2;
for(int i = 0; i < 10; i++);
{
result = result * 2;
}
return result;
}
}
| 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 | } |
| 24 |