2019-12-02 21:15:31
问题描述:
问题求解:
public String toHexspeak(String num) { StringBuffer sb = new StringBuffer(); char[] chs = new char[]{‘A‘, ‘B‘, ‘C‘, ‘D‘, ‘E‘, ‘F‘}; long n = Long.valueOf(num); while (n > 0) { int d = (int)(n % 16); if (d == 1) sb.append("I"); else if (d == 0) sb.append("O"); else if (d > 1 && d <= 9) return "ERROR"; else sb.append(chs[d - 10]); n = n / 16; } return sb.reverse().toString(); }
问题描述:
问题求解:
public String convertToBase7(int num) { if (num == 0) return "0"; StringBuffer sb = new StringBuffer(); boolean flag = num >= 0; num = num >= 0 ? num : -num; while (num > 0) { int d = num % 7; sb.append(d); num = num / 7; } return flag ? sb.reverse().toString() : "-" + sb.reverse().toString(); }
原文:https://www.cnblogs.com/hyserendipity/p/11973348.html