JAVA基础,从键盘上输入一串数字字符,将该数字字符转换成相应的二进制串,八进制串和十六进制串。

从键盘上输入一串数字字符,将该数字字符转换成相应的二进制串,八进制串和十六进制串。
用JAVA编写

很简单的
public class Test{
    private static void function7() {
        Scanner sc=new Scanner(System.in);
        int i=sc.nextInt();
        System.out.println("二进制:"+Integer.toBinaryString(i));
        System.out.println("八进制:"+Integer.toOctalString(i));
        System.out.println("十六进制:"+Integer.toHexString(i));
    }
}

追问

要这样的输出怎样修改一下呢?我是学文学的对这个有点无力= =

追答public class Test{
    private static void function7() {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入数字:");
        int i=sc.nextInt();
        System.out.println("二进制:"+Integer.toBinaryString(i));
        System.out.println("八进制:"+Integer.toOctalString(i));
        System.out.println("十六进制:"+Integer.toHexString(i));
    }
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-06-20
稍等片刻
码砖去追问

好的!