Homework time again. I have to create a program to print 1s and 2s complement of a binary number. So far is tis correct for 2s compliment? Should I allow input, then calculate 1's compliment before 2's?
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);
}
}