Hi,
I am doing an exercise of Head First Java Pool puzzle. I tried many times and finally got the output required but I am still not fully understand that how program produced that output.
The code for Pool Puzzle is as under:
class Echo {
int count = 0;
void hello() {
System.out.println("helloooo...");
}
}
public class EchoTestDrive {
public static void main (String []args) {
Echo e1 = new Echo();
Echo e2 = new Echo();
int x = 0;
while ( x < 4 ){
e1.hello();
e1.count = e1.count + 1;
if ( x > 0){
e2.count = e2.count + 1;
}
if ( x > 1) {
e2.count = e2.count + e1.count;
}
x = x + 1;
}
System.out.println(e2.count);
}
}
The program prints to the output is ;
helloooo...
helloooo...
helloooo...
helloooo...
10
=======================
Also if someone could tell me that how we can get the same output but instead of 10 we need 24.
I hope my question will be answered quickly.
Thank you.