zoukankan      html  css  js  c++  java
  • 7月面试笔试记录

    算法题

    1.将一个16进制的字符串转发为整型的数字

     1 /****
     2      * 将16进制字符串转化为10进制的整型
     3      * 
     4      * @param src
     5      * @return
     6      */
     7     public static double parseInt(String src) {
     8         double result = 0;
     9         int size = src.length();
    10         for (int i = size - 1, j = 0; i >=0; i--, j++) {
    11             result += charToInt(src.charAt(i)) * Math.pow(16, j);
    12         }
    13 
    14         return result;
    15     }
    16 
    17     public static int charToInt(char c) {
    18         int result = 0;
    19         switch (c) {
    20         case 'A'|'a':
    21             result = 10;
    22             break;
    23         case 'B'|'b':
    24             result = 11;
    25             break;
    26         case 'C'|'c':
    27             result = 12;
    28             break;
    29         case 'D'|'d':
    30             result = 13;
    31             break;
    32         case 'E'|'e':
    33             result = 14;
    34             break;
    35         case 'F'|'f':
    36             result = 15;
    37             break;
    38         default:
    39             result = Integer.parseInt(c + "");
    40             break;
    41         }
    42         return result;
    43     }

    jdk自带的方法一句话:Integer.valueOf(字符串,16)

    一起举例:

    1. 十进制转成十六进制:Integer.toHexString(int i)
    2. 十进制转成八进制:  Integer.toOctalString(int i)   
    3. 十进制转成二进制:Integer.toBinaryString(int i)    

    2.将1000以内能将3整除但不是偶数的找出来,并由大到小排序,ps 必须用到冒泡排序

        public static void main(String[] args) {
            List<Integer> result = new ArrayList<Integer>();
            for (int i = 0; i < 1001; i++) {
                if (i % 3 == 0 && i % 2 != 0) {
                    result.add(i);
                }
            }
            for (int i = 0; i < result.size(); i++) {
                for (int j = 0; j < result.size()-1; j++) {
                    int temp = result.get(j);
                    if (result.get(j) < result.get(j + 1)) {
                        result.set(j, result.get(j + 1));
                        result.set(j + 1, temp);
                    }
                }
            }
            System.out.println(result);
        }

     数据库

    1.查询表table1的数据字段number,除掉重复的数据并以number排序

       select distinct t.number from table1 as t order by t.number

    2.查询表table1的数据字段number,重复次数为2的,并排序

       select  t.number ,count(*)  from table1 as t group by t.number having count(*)>1

  • 相关阅读:
    搞懂分布式技术7:负载均衡概念与主流方案
    搞懂分布式技术6:Zookeeper典型应用场景及实践
    Django学习系列之django分页
    Python学习系列之format用法
    Python进阶系列之怎么写出pythonic的代码
    Python学习系列之内置函数
    域名添加HTTPS
    zabbix学习系列之QQ消息报警
    zabbix学习系列之配置邮件告警
    zabbix学习系列之触发器
  • 原文地址:https://www.cnblogs.com/flypig88/p/3190958.html
Copyright © 2011-2022 走看看