javaint转为⼆进制_Java程序将int转换为⼆进制字符串Java中的BinaryString()⽅法将int转换为⼆进制字符串。
假设以下是我们的整数值。int val1 = 9;
int val2 = 20;
int val3 = 2;
将上述int值转换为⼆进制字符串。BinaryString(val1);
⽰例public class Demo {
public static void main(String[] args) {
int val1 = 9;
int val2 = 20;
int val3 = 30;
int val4 = 78;
int val5 = 2;
System.out.println("Converting integer "+val1+" to Binary String: "+BinaryString(val1));
System.out.println("Converting integer "+val2+" to Binary String: "+BinaryString(val2));
System.out.println("Converting integer "+val3+" to Binary String: "+BinaryString(val3));
bigdecimal转换为integerSystem.out.println("Converting integer "+val4+" to Binary String: "+BinaryString(val4));
System.out.println("Converting integer "+val5+" to Binary String: "+BinaryString(val5));
}
}
输出结果Converting integer 9 to Binary String: 1001
Converting integer 20 to Binary String: 10100
Converting integer 30 to Binary String: 11110
Converting integer 78 to Binary String: 1001110
Converting integer 2 to Binary String: 10
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论