其他分享
首页 > 其他分享> > 十进制数转为二进制

十进制数转为二进制

作者:互联网

public class Ten Change Two {
public static void main(String[] args){
System.out.println(“请输入一个十进制的整数:”);
Scanner sc = new
Scanner(System.in);
double d = sc.nextDouble();
int z = (int)d;
double x = d-z;
long j = 1;
long sum = 0;
for(int i = z;i > 0;i = i/2){
sum += i%2j;
j
= 10;
}
double sumx = 0.0,k=0.1;
int h =1;
for(;;k/10){
x = (x-(int)x)2;
sumx += (int)x
k;
h++;
if(x - (int)x == 0.0)
break;
}
System.out.println(“转换为二进制的数值为:”+ (sum + sumx));

标签:sumx,二进制,double,sum,System,int,0.0,转为,十进制
来源: https://blog.csdn.net/m0_64175408/article/details/121985647