package com.easy;
import java.util.Scanner;
public class Easy {//类名首字母必须大写
public static void main(String[] args) {
//作业:手算45的二进制
int num;
Scanner sc = new Scanner(System.in);
num = sc.nextInt();
System.out.println(Transform(num));
sc.close();
}
public static String Transform(int a) {
String TempResult = "";
String result = "0b";
while(a != 0) {
TempResult += (a % 2 == 0) ? "0" : "1";
a /= 2;
}
for(int i = TempResult.length() - 1; i >= 0; i--) {
result += TempResult.charAt(i);
}
result += "\n";
return result;
}
}
Java第一天---二进制转换
最新推荐文章于 2024-08-31 10:44:02 发布