Java算法实现蜗牛援井(井深、攀爬距离、下滑距离)

package extraPractice;

import java.util.Scanner;

public class ASnail {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		System.out.print("请输入井深:");
		double wellDepth = sc.nextDouble();
		System.out.print("请输入蜗牛白天的攀爬距离:");
		double climb = sc.nextDouble();
		System.out.print("请输入蜗牛夜晚的下滑距离:");
		double glide = sc.nextDouble();
		int numOfDays = 0; // 天数
		double climbDistance = 0.0; // 总爬行距离
		for (int i = 1; i >= 0; i++) {
			climbDistance += climb;
			if (climbDistance >= wellDepth) {
				numOfDays = i;
				break;
			}
			climbDistance -= glide;
		}
		System.out.println("提示:蜗牛需要" + numOfDays + "天才能爬到井口!");

	}

}

你可能感兴趣的:(典化成籍-Java)