public class EchoTestDrive {
public static void main(String[] args) {
Echo e1 = new Echo();
Echo e2 = new Echo(); //Echo e2 = e1也可以
int x = 0;
while(x<4){
e1.hello();
e1.count=e1.count+1;
if(x==3){
e2.count=e2.count+1;
}
if (x>0){
e2.count=e2.count+e1.count;
}
x=x+1;
}
System.out.println(e2.count);
}
}
class Echo{
int count=0;
void hello(){
System.out.println("helloooo...");
}
}为什么最后的输出是
helloooo...
helloooo...
helloooo...
helloooo...
10这个10是怎么算出来的,我不太明白e1.count这个表达式是什么意思,值是多少?
public static void main(String[] args) {
Echo e1 = new Echo();
Echo e2 = new Echo(); //Echo e2 = e1也可以
int x = 0;
while(x<4){
e1.hello();
e1.count=e1.count+1;
if(x==3){
e2.count=e2.count+1;
}
if (x>0){
e2.count=e2.count+e1.count;
}
x=x+1;
}
System.out.println(e2.count);
}
}
class Echo{
int count=0;
void hello(){
System.out.println("helloooo...");
}
}为什么最后的输出是
helloooo...
helloooo...
helloooo...
helloooo...
10这个10是怎么算出来的,我不太明白e1.count这个表达式是什么意思,值是多少?
/**
*
* @ClassName:Echo
* x e1.count e2.count
* 0 1 0
* 1 2 0+2=2
* 2 3 2+3=5
* 3 4 (x==3)5+1=6,6+4=10; over
*/