AcWing 1504. 火星颜色(Java)
原题链接
简单
作者:
码海泛舟
,
2020-07-22 12:30:48
,
所有人可见
,
阅读 652
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] a = new int[3];
for (int i = 0; i < 3 ;i++) a[i] = sc.nextInt();
System.out.print("#");
for (int i = 0; i < 3 ;i++) {//将每个a[i]转为13进制
System.out.print(get(a[i] / 13));
System.out.print(get(a[i] % 13));
}
System.out.println();
}
private static char get(int n) {
if (n <= 9) return (char)('0' + n);//[0,9]直接返回
return (char)('A' + (n - 10));//转为对应的字母
}
}