zoukankan      html  css  js  c++  java
  • 蓝桥杯- 基础练习:十进制转十六进制

    package shiti;
    
    import java.util.Scanner;
    
    //十进制转十六进制
    public class D {
        public static void main(String[] args) {
            Scanner cin = new Scanner(System.in);
            int n = cin.nextInt(), m = 0;
            char c;
            String s = "";
            if (n == 0)  //如果输入为0 , 那么结果也为0 
                s = "0";
            while (n % 16 != 0 || n / 16 != 0) {
                m = n % 16;
                if (m / 10 == 1)
                    c = (char) (65 + m % 10);
                else
                    c = (char) (48 + m);
                s = c + s;
                n = n / 16;
            }
            System.out.println(s);
        }
    }
    package shiti;
    
    import java.util.Scanner;
    
    public class D1 {
    
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            long nextLong = scanner.nextLong();
            StringBuffer string = new StringBuffer();
            Long midLong = 0l;
            char midchar;
            if (nextLong == 0) {
                string.append("0");
            }
            while (nextLong / 16 != 0 || nextLong % 16 != 0) {
                midLong = nextLong % 16;
                if (midLong / 10 == 1) {
                    midchar = (char) (65 + (midLong % 10));
                } else {
                    midchar = (char) (midLong + 48);
    
                }
                string.insert(0, midchar);
                nextLong /= 16;
            }
            System.out.println(string);
        }
    }
  • 相关阅读:
    socket套接字通信和粘包问题
    TCP协议
    网络编程
    单例模式
    类的内置方法(魔法方法)
    反射(hasattr和getattr和setattr和delattr)
    isinstance与issubclass
    绑定方法与非绑定方法
    鸭子类型
    类的多态和抽象类
  • 原文地址:https://www.cnblogs.com/wzqjy/p/8284219.html
Copyright © 2011-2022 走看看