参考代码:
import java.util.Scanner; public class 进制转换 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub //1892: [蓝桥杯][算法提高VIP]P0102 Scanner scanner=new Scanner(System.in); String s1=scanner.next(); int n=Integer.parseInt(s1,16); System.out.println("Hex: 0x"+s1); System.out.println("Decimal: "+n); System.out.print("Octal: "); if (Integer.toOctalString(n).length()<4) { for (int i = 0; i < 4-Integer.toOctalString(n).length(); i++) { System.out.print("0"); } } System.out.print(Integer.toOctalString(n)); } }
0.0分
1 人评分