Discuss / Java / 写一个只用Deque实现的

写一个只用Deque实现的

Topic source

ElGordo

#1 Created at ... [Delete] [Delete and Lock User]

import java.util.*;

public class Main {

    public static void main(String[] args) {

        String hex = toHex(12500);

        if (hex.equalsIgnoreCase("30D4")) {

            System.out.println("测试通过");

        } else {

            System.out.println("测试失败");

        }

    }

    static String toHex(int n) {

    int temp = 1;

    Deque<String> deque = new LinkedList<>();

    String s = "";

    while(n != 0) {

    temp = n % 16;

    n = n / 16;

    deque.push(Integer.toHexString(temp)); //用大轮子重新画了个小轮子,haha

    }

    do {

    if(deque.peek() != null) {

    s = s + deque.peek();

    }

    }while(deque.poll() != null);

        return s;

    }

}


  • 1

Reply