访友

小易准备去拜访他的朋友,他的家在0点,但是他的朋友的家在x点(x > 0),均在一条坐标轴上。小易每一次可以向前走1,2,3,4或者5步。问小易最少走多少次可以到达他的朋友的家?

思路:如果距离小于6则,一步可达,如果大于6,则先走5步

private static void calc(int n) {
        int count = 0;
        while (n > 5){
            count++;
            n -= 5;
        }
        if(n > 0){
            count++;
        }
        System.out.println(count);
}
原文地址:https://www.cnblogs.com/dongma/p/13442794.html