Tech Talk Binary Addition
import java.util.Scanner;
public class BinaryAddition {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Read the first binary number from the user
System.out.print("Enter the first binary number: ");
System.out.println(a);
String binaryString1 = scanner.nextLine();
// Read the second binary number from the user
System.out.print("Enter the second binary number: ");
System.out.println(a);
String binaryString2 = scanner.nextLine();
// Convert the binary numbers to integers
int a = Integer.parseInt(binaryString1, 2);
int b = Integer.parseInt(binaryString2, 2);
// Add the binary numbers and convert the result to binary
int sum = a + b;
String binaryResult = Integer.toBinaryString(sum);
// Display the binary result
System.out.println("The sum of " + binaryString1 + " and " + binaryString2 + " is " + binaryResult + " in binary.");
}
}
BinaryAddition.main(null);