为什么我条件没有满足,循环却停止了?public class Snail { /**
 * @param args
 */

public static void main(String[] args) {
// TODO Auto-generated method stub
int x = 2;
double distance = 3;
double lon = 1000;
do{
 x = x + 1;
 lon = x * 1000;
 distance = (lon * (distance / ((x - 1) * 1000))) + 1;
}while(distance > lon);
}
}

解决方案 »

  1.   

             System.out.println(x);
             System.out.println(distance);
             System.out.println(lon);
    你在while结束前加上看看,就知道了,循环已经满足了
      

  2.   

    就是因为条件不满足,才只执行了一次啊!
      do{}while();
        是先执行循环体,再判断条件!
           如果while();条件满足的话,就会继续执行.不满足,则循环停止!
      

  3.   


    distance = (lon * (distance / ((x - 1) * 1000))) + 1; 
    后面加一行
    System.out.println(distance > lon);
      

  4.   

    while(distance > lon); 
    当 while  为 true 继续 执行
               为 false 则退出
      

  5.   

    public class Snail { /** 
     * @param args 
     */ public static void main(String[] args) { 
    // TODO Auto-generated method stub 
    int x = 2; 
    double distance = 3; 
    double lon = 1000; 
    do{ 
     x = x + 1; 
     lon = x * 1000; 
     distance = (lon * (distance / ((x - 1) * 1000))) + 1; 
    }while(distance > lon); 
    System.out.println(distance);
    System.out.println(x);
    System.out.println(lon);

    }
    你没有控制太输出语句啊
    而且distance<lon
      

  6.   

    distance <lon 所以程序退出