ttpn

导航

 

题目

 

思路:使用递归。

 1 import java.util.Scanner;
 2 class test 
 3 {
 4     static void tohex(int a)
 5     {
 6        if(a/16>=1)//先得到余数的是低位,低位后打印
 7            tohex(a/16);
 8 
 9        if(a%16>9)
10            System.out.printf("%c",a%16+55);//大于9转化为ABCDEF
11        else
12            System.out.printf("%d",a%16);
13     }
14     public static void main(String[] args) 
15     {
16         int a;
17         Scanner scanner=new Scanner(System.in);
18         System.out.printf("输入a=");
19         a=scanner.nextInt();
20         tohex(a);
21         return;
22     }
23 }

 

posted on 2017-02-21 13:09  Buzhou  阅读(303)  评论(0编辑  收藏  举报