Extra Seed Work
Extra Seed Work
import java.util.Scanner;
public class BinaryAddition {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Read the first number
System.out.println("Enter the first number: ");
int num1 = scanner.nextInt();
// Read the second number
System.out.println("Enter the second number: ");
int num2 = scanner.nextInt();
// Add the numbers
int sum = num1 + num2;
// Convert the sum to binary
String binary = "";
int quotient = sum;
int remainder;
while (quotient != 0) {
remainder = quotient % 2; // Find the remainder of quotient / 2
binary = remainder + binary; // Add the remainder to the beginning of the binary string
quotient = quotient / 2; // Update the quotient by dividing by 2
}
// Display the sum in binary
System.out.println("The sum in binary is: " + binary);
scanner.close(); // Close the scanner
}
}
BinaryAddition.main(null);