解题思路: 字符串与二进制
注意事项: 注意负数
参考代码:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); while(in.hasNext()) { int n=in.nextInt(); if(n>=0) System.out.println(n+"-->"+Integer.toBinaryString(n)); else { int num =Integer.parseInt(Integer.toString(n).substring(1)); System.out.println(n+"-->-"+Integer.toBinaryString(num)); //注意负数的处理 } } in.close(); } }
0.0分
0 人评分
大神老白 (C语言代码)浏览:715 |
C语言训练-排序问题<1> (C++代码)浏览:602 |
A+B for Input-Output Practice (IV) (C++代码)浏览:677 |
字符串对比 (C语言代码)浏览:1413 |
计算质因子 (C++代码)浏览:1644 |
母牛的故事 (C语言代码)浏览:934 |
C语言程序设计教程(第三版)课后习题6.11 (C语言代码)浏览:2081 |
C语言程序设计教程(第三版)课后习题7.4 (C语言代码)浏览:1246 |
C语言程序设计教程(第三版)课后习题6.3 (C++代码)浏览:963 |
C语言程序设计教程(第三版)课后习题11.1 (C语言代码)浏览:622 |