本帖最后由 林铁柱 于 2012-2-14 09:16 编辑
import java.util.Random;
public class MyMain {
/**
* @param args
*/
int panZi = 0;
Random random = new Random();
static MyMain mymain = new MyMain();
public static void main(String[] args) {
mymain.a2();
}
public void a1(){
int j=0;
if(panZi==0){
j = random.nextInt(10);
if(j>0){
panZi =panZi + j;
System.out.println("爸爸放了"+j+"个苹果");
}
}
mymain.a2();
}
public void a2(){
if(panZi>0){
System.out.println("爸爸等着孩子拿苹果");
System.out.println("孩子拿走一个苹果");
panZi--;
}
mymain.a1();
}
} |