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 宝宝100日简短祝福语
11 送礼祝福语男性生日简短
12 学生祝福语简短古诗句
13 简短佛教新年祝福语大全
14 初八的祝福语简短
15 哥哥中考加油祝福语简短
16 科研文案祝福语简短励志
17 敏字的祝福语简短
18 简短古文生日祝福语