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 出阁宴祝福语姐姐简短