又是作业时间。我必须创建一个程序来打印二进制数的 1 和 2 补码。到目前为止,2s 恭维是正确的吗?我应该允许输入,然后在 2 之前计算 1 的恭维吗?
import java.util.Scanner;
public class BitWiseComplement {
public static void main (String [] args) {
String a = "1";
String b = "0";
Scanner reader = new Scanner(System.in);
String binary;
String binary2;
System.out.println("Please enter your binary number:");
binary = reader.nextLine();
binary2 = binary.replaceAll(a, b);
System.out.println(binary2);
}
}