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 红包祝福语简短10字
18 周六早晨祝福语简短