Extra Credit Seed Opportunity

  • Write a sample binary addition 1 + 1 = 10
  • Have Java Code cell on screen at start of lecture
  • Don't tell anyone
import java.util.Scanner;

public class BinaryAdding {

	private static Scanner scanner;
	
	public static void main(String[] args) {

		scanner = new Scanner(System.in);
		
		System.out.println("Enter first and second numbers");	
		String b1 = scanner.nextLine();
		System.out.println(b1);
		String b2 = scanner.nextLine();
		System.out.println(b2);
		
		int num1 = Integer.parseInt(b1, 2);
		int num2 = Integer.parseInt(b2, 2);
		
		int output = num1 + num2;
		
		System.out.print("\nThe Sum = ");
		System.out.print(Integer.toBinaryString(output));
	}
}

BinaryAdding.main(null);
Enter The First and Second Numbers = 
1
1

The Sum = 10