日期:2014-05-20 浏览次数:20694 次
String s = Integer.toString(728, 3); byte[] bytes = s.getBytes(); for(int i = 0; i < bytes.length; i++){ System.out.println(bytes[i]); bytes[i] = (byte)(bytes[i] + 17); } System.out.println(new String(bytes));
------解决方案--------------------
for example
public class csdn { public static void main(String[] args) throws Throwable { String s = "222222"; System.out.println(Integer.parseInt(s, 3)); System.out.println(toString(728, 3)); } public static String toString(int n, int radix) { char[] dig = {'A', 'B', 'C'}; if (radix > dig.length) {return "100000";} String s = Integer.toString(n, radix); StringBuilder buf = new StringBuilder(); for (char c : s.toCharArray()) { buf.append(dig[c-'0']); } return buf.toString(); } }
------解决方案--------------------
String s = Integer.toString(728, 3);
byte[] bytes = s.getBytes();
for(int i = 0; i < bytes.length; i++){
System.out.println(bytes[i]);
bytes[i] = (byte)(bytes[i] + 17);
}
System.out.println(new String(bytes));
------解决方案--------------------
[code=Java][/code]
System.out.println("输入要处理的数字(最大值728):");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
Integer co = Integer.parseInt(s);
if(co <= 728){
String ss = Integer.toString(co, 3);
byte[] by = ss.getBytes();
for(int i=0; i<by.length; i++){
by[i] = (byte)(by[i] + ('A' - '0'));
}
System.out.println(new String(by));
}else
System.out.println("请输入不大于728的数!");
------解决方案--------------------
System.out.println("输入要处理的数字(最大值728):"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = br.readLine(); Integer co = Integer.parseInt(s); if(co <= 728){ String ss = Integer.toString(co, 3); byte[] by = ss.getBytes(); for(int i=0; i<by.length; i++){ by[i] = (byte)(by[i] + ('A' - '0')); } System.out.println(new String(by)); }else System.out.println("请输入不大于728的数!");