Discuss / Java / 写个代码

写个代码

Topic source

ncoheart

#1 Created at ... [Delete] [Delete and Lock User]

这种写法应该挺简洁的了

import java.util.*;

public class Main {
    public static void main(String[] args) {
        String hex = toHex(12500);
        if (hex.equalsIgnoreCase("30D4")) {
            System.out.println("测试通过");
        } else {
            System.out.println("测试失败");
        }
    }

    static String toHex(int n) {
        String alpha = "0123456789ABCDEF";
        if (n < 16){
            return String.valueOf(alpha.charAt(n));
        }
        return toHex(n/16)+String.valueOf(alpha.charAt(n%16));
    }
}

AlaGeek

#2 Created at ... [Delete] [Delete and Lock User]

用了系统栈,6666

浪过扬帆

#3 Created at ... [Delete] [Delete and Lock User]

妙啊,铁子


  • 1

Reply