题解 | #牛群编号转换#

牛群编号转换

https://www.nowcoder.com/practice/6a5ed8ca0a454e3a93f5e2b2e7502651

import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param num int整型 
     * @return string字符串
     */
    public String convert_to_base6 (int num) {
        // write code here
        if(num==0){
            return "0";
        }
        String str="";
        int record=Math.abs(num);
        while(record>0){
            int y=record%6;
            str=y+str;
            record/=6;
        }
        if(num<0){
            return "-"+str;
        }
        return str;
    }
}

全部评论

相关推荐

A_SOUL_Off...:疑似加班加出幻觉了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务