C语言趣味程序百例精解之java实现(95)将阿拉伯数翻译成罗马数字
程序:
public class Test95{
static String a[][]={{"","I","II","III","IV","V","VI","VII","VIII","IX"},
{"","X","XX","XXX","XL","L","LX","LXX","LXXX","XCC"},
{"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"}};
public static void main(String args[]){
int n=Integer.parseInt(args[0]);
int t=0;
System.out.printf("%d=",n);
for(int m=0,i=1000;m<3;m++,i/=10){
t=(n%i)/(i/10);
System.out.printf("%s",a[2-m][t]);
}
System.out.printf("\n");
}
}
运行:
C:\bat>java Test95 353
353=CCCLIII
C:\bat>java Test95 863
863=DCCCLXIII
C:\bat>java Test95 256
256=CCLVI
C:\bat>java Test95 355
355=CCCLV
C:\bat>java Test95 522
522=DXXII
C:\bat>java Test95 15
15=XV |