zoukankan      html  css  js  c++  java
  • Int2BinaryString.java

    /******************************************************************************
    * Compilation: javac Int2BinaryString.java
    * Execution: java Int2BinaryString n
    *
    * Prints out n in binary.
    *
    * % java Int2BinaryString 5
    * 101
    *
    * % java Int2BinaryString 106
    * 1101010
    *
    * % java Int2BinaryString 0
    * 0
    *
    * % java Int2BinaryString 16
    * 10000
    *
    * Limitations
    * -----------
    * Does not handle negative integers or 0.
    *
    * Remarks
    * -------
    * could use Integer.toBinaryString(n) instead.
    *
    ******************************************************************************/

    public class Int2BinaryString {
    public static void main(String[] args) {
    int n = Integer.parseInt(args[0]);

    // repeatedly divide by two, and form the remainders backwards
    String s = "";
    for (int i = n; i > 0; i /= 2) {
    s = (i % 2) + s;
    }
    System.out.println(s);
    }
    }

  • 相关阅读:
    too many open files linux服务器 golang java
    fasthttp 文档手册
    syncer.go
    grpc.go
    stm.go
    session.go
    mutex.go
    [HTML5]label标签使用以及建议
    禁止使用finalize方法
    [支付宝]手机网站支付快速接入
  • 原文地址:https://www.cnblogs.com/bayes/p/9663321.html
Copyright © 2011-2022 走看看