Java程序将十进制数转换为二进制值
java.lang.Integer类将原始类型int的值包装在对象中。类型为Integer的对象包含一个类型为int的字段。
Integer类的toBinaryString()方法将整数参数的字符串表示形式作为基数中的无符号整数返回
示例
import java.util.Scanner;
public class DecimalToBinary {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.println("Enter a decimal number ::");
int decimal = sc.nextInt();
String result = Integer.toBinaryString(decimal);
System.out.println("Binary value of the given decimal number is ::"+result);
}
}输出结果
Enter a decimal number :: 444 Binary value of the given decimal number is ::110111100
热门推荐
10 广西考试祝福语结婚简短
11 猪年祝福语简短小孩
12 元旦祝福语送长辈简短
13 恭喜二宝祝福语简短
14 祝福语暖心话简短
15 国庆中秋祝福语简短兄弟
16 朋友订婚的祝福语简短
17 送弟弟中秋祝福语简短
18 爱生日祝福语简短独特