题解 | #神奇牛的体重#

神奇牛的体重

https://www.nowcoder.com/practice/456d819bb5b3440eb147296dbfa7af80

知识点

函数使用

解题思路

使用Math.pow方法来计算牛的体重。根据题目的描述,经过m天后,牛的体重变为n * m * m公斤。使用Math.pow(m, 2)来计算m的平方。然后,将牛的初始体重n与m的平方相乘得到体重的精确值。最后,使用Math.round方法将体重四舍五入到整数,并返回结果。

Java题解

import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     *
     * @param n int整型
     * @param m int整型
     * @return long长整型
     */
    public long weightAfterMDays (int n, int m) {
        // write code here
        double weight = n * Math.pow(m, 2);
        long roundedWeight = Math.round(weight);
        return roundedWeight;
    }
}

全部评论

相关推荐

哥_留个offer先:跟他说,你这个最好用c#,微软就用c#Java不适合这个项目
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务