16分版:
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int red=scanner.nextInt();
int green=scanner.nextInt();
int blue=scanner.nextInt();
System.out.println("#"+translate(red)+translate(green)+translate(blue));
}
static String translate(int num){//10进制的数转化为13进制的字符串
String str="";
while (num!=0){
int rem=num%13;
if (rem>10){
str=(char)('A'+rem-10)+str;
}
else {
str=rem+str;
}
num/=13;
}
if (str.length()==0){
str="00";
}
if (str.length()==1){
str='0'+str;
}
return str;
}
}
20分版:
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int red = scanner.nextInt();
int green = scanner.nextInt();
int blue = scanner.nextInt();
String string = Integer.toString(red, 13).toUpperCase();
String string2 = Integer.toString(green, 13).toUpperCase();
String string3 = Integer.toString(blue, 13).toUpperCase();
StringBuffer sb1 = new StringBuffer(string);
StringBuffer sb2 = new StringBuffer(string2);
StringBuffer sb3 = new StringBuffer(string3);
if(string.length()==1) {
sb1.insert(0, "0");
}
if(string2.length()==1) {
sb2.insert(0, "0");
}
if(string3.length()==1) {
sb3.insert(0, "0");
}
System.out.print("#"+sb1+sb2+sb3);
}
}