public class DecimalBinary { public static void main(String[] args) { int num = 19; long binary = convertDecimalToBinary(num); System.out.printf("%d 十进制 = %d 二进制", num, binary); } public static long convertDecimalToBinary(int n) { long binaryNumber = 0; int remainder, i = 1, step = 1; while (n!=0) { remainder = n % 2; System.out.printf("Step %d: %d/2, 余数 = %d, 商 = %d ", step++, n, remainder, n/2); n /= 2; binaryNumber += remainder * i; i *= 10; } return binaryNumber; } }
版权声明:
本文来源网络,所有图片文章版权属于原作者,如有侵权,联系删除。
本文网址:https://www.bianchenghao6.com/java-jiao-cheng/12011.html