本帖最后由 Up↑Lee↗ 于 2014-3-18 16:04 编辑
- class ArrayTest3
- {
- public static void main(String[] args)
- {
- toBin(6);
- }
- /*
- 十进制---->二进制
- */
- public static void toBin(int num)
- {
- StringBuffer sb = new StringBuffer();
- while(num>0)
- {
- //System.out.println(num%2);
- sb.append(num%2);
- num = num / 2;
- }
- System.out.println(sb.reverse());
- }
- }
复制代码
结果应该是 :110啊
|