Discuss / Java / 练习1—打卡

练习1—打卡

Topic source

package test;

import java.util.*;

public class Main {

    public static void main(String[] args) {

        String hex = toHex(12500);

        System.out.println(hex);

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

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

        } else {

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

        }

    }

    static String toHex(int n) {

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

    while(n!=0) {

    deque.push(Integer.toHexString(n%16));

    n=n/16;

    }

    StringBuilder sb=new  StringBuilder();

    for (String s:deque) {

    sb.append(s);

    }

        return sb.toString();

    }

}


  • 1

Reply