package step1; /** * created by zengpeng on 2018/2/9. */ public class binary
时间: 2023-10-27 08:02:47 浏览: 83
package step1;
/**
* created by zengpeng on 2018/2/9.
*/
public class binary {
public static void main(String[] args) {
int num = 10;
String binaryString = decimalToBinary(num);
System.out.println("十进制数 " + num + " 的二进制表示为:" + binaryString);
}
public static String decimalToBinary(int num) {
String binaryString = "";
while (num > 0) {
binaryString = num % 2 + binaryString;
num = num / 2;
}
return binaryString;
}
}
阅读全文